![](/img/trans.png)
[英]Smooth scroll isn't smooth at all; smooth scroll only scrolls a number of pixels and not to the specified div
[英]smooth scroll only scrolls to one element
我对所有这些都是新手,但是我只是想做我的网站,所以当您单击与图像相关的一天中的时间(链接)时,它会平滑地滚动到该图像。 我的问题是,当我这样做时,每个链接都会滚动到同一张图片。
Java脚本
$(function(){
$('body').css({marginTop: $('ul').height()});
$('.scroller-link').click(function(e){
e.preventDefault();
id = $(this).attr('href').replace('#', '');
$('html,body').animate({scrollTop: $("#"+id).offset().top-$(this).closest('ul').height()},'slow');
});
的HTML
<Body>
<ul>
<a href="#1" class="scroller-link">9AM</a>
<a href="#2" class="scroller-link">11AM</a>
</ul>
<div id="1">
<a> <img src="images/9am.jpg" /></a>
</div>
<div id="2">
<a> <img src="images/11am.jpg" /></a>
</div>
换句话说,当我单击“ 11AM”链接时,它仍然转到9AM图像。
提前致谢!
您不需要重新发明轮子。 您可以使用像这样的微型库: ScrollIt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.