Answer the question
In order to leave comments, you need to log in
jQuery smooth scrolling - what's wrong with me?
Hello!
I can't figure out why smooth scrolling doesn't work. I don’t understand js, but I found a ready-made code, it is quite popular with search engines.
Having done everything according to the instructions, I got only an html anchor - it goes to the right place without animation. ..index.php#g-feature is added to the address bar. I
assume that the problem is in the script itself, but I don’t know what exactly needs to be changed.
I include the script between the head tags:
<script type="text/javascript">
$(document).ready(function() {
$('a[href^="#"]').click(function () {
elementClick = $(this).attr("href");
destination = $(elementClick).offset().top;
if($.browser.safari){
$('body').animate( { scrollTop: destination }, 1100 );
}else{
$('html').animate( { scrollTop: destination }, 1100 );
}
return false;
});
});
</script>
<a class="g-menu-item-container" href="#g-feature">
<span class="g-menu-item-content">
<span class="g-menu-item-title">Преимущества</span>
</span>
</a>
<section id="g-feature">
....
</section>
Answer the question
In order to leave comments, you need to log in
$(document).ready(function(){
$('a[href*=#]').bind("click", function(e){
var anchor = $(this);
$('html, body').stop().animate({
scrollTop: $(anchor.attr('href')).offset().top
}, 1000);
e.preventDefault();
});
return false;
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question