mka*_*yan 1 html javascript jquery
我在firefox和IE中的scrolltop有一些问题我在我的代码中使用了scrolltop超过2次它在第一部分它可以工作但在第二部分它不是我有两个箭头"next"和"prev"当点击它们页面滚动到具体部分,我无法找到如何解决它?
jquery:
var lchiled=$("ul#portfolio li").last();
var fchiled=$("ul#portfolio li").first();
$('li.section').first();
$("ul#portfolio li:first-child").addClass("current");
$('a.display').on('click', function(e) {
e.preventDefault();
var t = $(this).attr('name');
that = $(this);
if (t === 'next') {
if($('.current').next('.section').length==0)
var $next = $('li.section').first();
else
var $next = $('.current').next('.section');
var top = $next.offset().top -65;
$('.current').removeClass('current');
$('body,html').animate({
scrollTop: top,
},
function () {
$next.addClass('current');
// alert(top);
});
}
else if (t === 'prev' && $('.current').prev('li.section').length > 0) {
var $prev = $('.current').prev('.section');
var top = $prev.offset().top -65;
$('.current').removeClass('current');
$('body').animate({
scrollTop: top,
}, function () {
$prev.addClass('current');
});
}
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<div id="container">
<ul id="portfolio" class="clearfix">
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
lis是用jquery代码动态生成的
一定是这样的
$('body,html').animate({
scrollTop: top,
}, function () {
$prev.addClass('current');
});
Run Code Online (Sandbox Code Playgroud)
绝对的
$('body').animate({
scrollTop: top,
}, function () {
$prev.addClass('current');
});
Run Code Online (Sandbox Code Playgroud)
我忘了更新prev部分,所以这个问题发生了.
| 归档时间: |
|
| 查看次数: |
2732 次 |
| 最近记录: |