2016-06-14 36 views
0
$('a[href="#two"]').click(function(e) { 
     e.preventDefault(); 
     var targetOffset = $('div[id="two"]').offset().top; 
     $('body').animate(
      {scrollTop: targetOffset}, 
      1000 
      ); 
    }); 

我在這裏有一個代碼,順利滾動到div錨點。它在IE(11)中不起作用。在Chrome/Firefox中運行良好。有人可以幫我:DjQuery動畫錨定腳本不在IE中工作

+0

你見過這個:http://stackoverflow.com/questions/29153607/jquery-scrolltop-not-working-in-ie11 – vijayP

回答

0

這似乎工作。

$(function() { 
    $('a[href*="#"]:not([href="#"])').click(function() { 
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { 
     var target = $(this.hash); 
     target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); 
     if (target.length) { 
     $('html, body').animate({ 
      scrollTop: target.offset().top 
     }, 1000); 
     return false; 
     } 
    } 
    }); 
});