Jump to content

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

Go to solution Solved by Beyondspace,

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
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution
$(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)
🗓️ Delivery Date Picker (Squarespace Date format)
💫 Animated Buttons (Referral URL)
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • 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.