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

Ich habe hier einen Code, der reibungslos zum Div-Anker scrollt. Es funktioniert nicht in IE (11). Funktioniert gut in Chrome/Firefox. Kann mir jemand aushelfen: DjQuery zu verankern Skript funktioniert nicht in IE

+0

haben Sie gesehen: http://stackoverflow.com/questions/29153607/jquery-scrolltop-not-working-in-ie-11 – vijayP

Antwort

0

Das scheint zu funktionieren.

$(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; 
     } 
    } 
    }); 
}); 
Verwandte Themen