Reputation: 1
I found the code by Mary Lou http://tympanus.net/codrops/2010/06/02/smooth-vertical-or-horizontal-page-scrolling-with-jquery I try to add the animation automatically after 5 seconds. Unfortunately, to no avail.
Can I ask for help, and adding these lines. I am not a programmer and do not really know what else I can odd tricks.
$(function() {
$('ul.nav a').bind('click',function(event){
var $anchor = $(this);
$('html, body').stop().animate({
scrollLeft: $($anchor.attr('href')).offset().left
}, 1000);
event.preventDefault();
});
});
THX dede
Upvotes: 0
Views: 200
Reputation: 7549
The 1000
within the animate
sets the animation duration, so if you want to wait BEFORE the animation stars, you should use: delay(5000)
like this:
$(function() {
$('ul.nav a').bind('click',function(event){
var $anchor = $(this);
$('html, body').stop().delay(5000).animate({
scrollLeft: $($anchor.attr('href')).offset().left
}, 1000);
event.preventDefault();
});
});
If delay
doesn't work, try to write idle
instead of delay.
If you want the animation to work when clicking OR 5 seconds rihgt after the page is loaded, you should do this:
$(document).ready(function () {
$('ul.nav a').bind('click',function(event){
var $anchor = $(this);
$('html, body').stop().animate({
scrollLeft: $($anchor.attr('href')).offset().left
}, 1000);
event.preventDefault();
});
var $anchor = $('ul.nav a');
$('html, body').stop().delay(5000).animate({
scrollLeft: $($anchor.attr('href')).offset().left
}, 1000);
event.preventDefault();
});
Hope this is helpful !
Upvotes: 1