Jump to content

Redirect to *New Page* on scroll - how to add time delay?

Recommended Posts

Hey y'all - very new to jquery here. I found this jquery posted on Stack Overflow on how to redirect the user to a new page once they have scrolled to the bottom of the original page with the following code:

$(window).scroll(function() {

if ($(window).scrollTop() + $(window).height() == $(document).height()) window.location = "page2.html";
});

However, I'd like the function to delay for about 2 seconds so the transition isn't so jarring. I've tried to implement setTimeout, but still don't have a solid grasp on jQuery syntax/language to figure it out. Would love any help, thank you!

Link to comment
  • Replies 2
  • Views 1.5k
  • Created
  • Last Reply
$(window).scroll(function() {

	if ($(window).scrollTop() + $(window).height() == $(document).height()) {
    	setTimeout(function() {
			window.location = "page2.html";
		}, 2000);
    }
});

try

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox, video lightbox and much more)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 No-code customisations for Squarespace (+100 Spark plugin customisations)
🥳 Freemium Squarespace Widget Templates (+1000 Elfsight Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

Link to comment
3 hours ago, bangank36 said:
$(window).scroll(function() {

	if ($(window).scrollTop() + $(window).height() == $(document).height()) {
    	setTimeout(function() {
			window.location = "page2.html";
		}, 2000);
    }
});

try

Ahh - that placement makes a lot of sense. That worked, thanks so much for your help!

Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.