Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0

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


MayaViolet

Question

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

Top Posters For This Question

2 answers to this question

Recommended Posts

  • 0
$(window).scroll(function() {

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

try

Greeting, it's BaNgan from BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Youtube Gallery for Squarespace
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment
  • 0
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

Create an account or sign in to comment

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


×
×
  • Create New...