2014-03-26 38 views
1

我在Firefox和IE浏览器中的scrolltop有一些问题 我在我的代码中使用了scrolltop超过2次它的工作原理,但在第二部分中并没有 我有两个箭头“next”和“prev”,当他们点击页面滚动到特定部分, 我找不到我该如何解决它?scrollTop不能在Firefox和IE中工作

的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'); 
     }); 
    } 

}); 

HTML:

<div id="container"> 

    <ul id="portfolio" class="clearfix"> 

    </ul> 

</div> 

LIS动态与jquery代码

+0

你有一个链接,我们可以看到这个(用CSS)? – mayrop

+0

@mayrop不,它是本地的 – mkafiyan

回答

6

它必须是这样的

$('body,html').animate({ 
     scrollTop: top,  
    }, function() { 
     $prev.addClass('current'); 
    }); 

insted的的

$('body').animate({ 
     scrollTop: top,  
    }, function() { 
     $prev.addClass('current'); 
    }); 

我忘了所以这个问题发生在更新上一个部分。

-1

产生尝试var offset = $(window).scrollTop();这一点。

+0

它剂量的答案,但我找到了问题! – mkafiyan

+0

@Ashwani,这是比实际答案更多的评论。请使用评论选项,如果你没有足够的声望,请等待,直到你得到它。 –

1

您在两个位置上scrollTop使用.animate可以使用。在一个中,您(正确)使用html,body作为选择器。另一方面,您只能使用body。你想知道为什么它在某些浏览器中不起作用;)

+0

是的,正确的...... – mkafiyan

相关问题