jquery animate scrollTop函数无法在Internet Explorer中运行

Sur*_*ttu 17 javascript jquery internet-explorer

我正在使用此代码:

$('#goto_introduction_divcontent').click(function(){    
    var targetOffset = $('#introduction_div').offset().top;    
    $('html, body').animate({scrollTop:targetOffset}, 'slow');    
    if ($.browser.msie){    
        document.documentElement.scrollTop = targetOffset;  
    }  
});   
Run Code Online (Sandbox Code Playgroud)

但这不适用于Internet Explorer.我的jsFiddle就在这里.

小智 45

这在IE8 +中适用于我:

$('body, html').animate({ scrollTop: 0 }, 'slow');
Run Code Online (Sandbox Code Playgroud)

也许你的IF声明正在抛弃它?

  • 生命保护!我尝试了window.parent,window.parent.document,window.parent.document.$("body")等的每一个组合,但是在我看到这个之前没有想过尝试html - html在IE中工作,正文工作在我们支持的所有其他浏览器:) (4认同)
  • `html`选择器在IE11中为我做了诀窍.谢谢负载. (2认同)