Geschichte. Replacestate undefined IE11Jquery

JQuery-Programmierung
Anonymous
 Geschichte. Replacestate undefined IE11

Post by Anonymous »

Ich verwende den ScrollSpy von Bootstrap, um das Navigh -Element auf der Seite Scroll zu ändern und dann History zu verwenden. Diese Frage gab mir die Idee für diesen Teil. Ich verwende auch ein JQuery, um einen 'Smooth Scroll' zu implementieren, wenn ein Navigationselement geklickt wird, und ich schalte den ScrollSpy aus, während ich 'Smooth Scrolling' zum Anker nach unten schalte. Dann füge der Hash in die URL hinzu und scrollspy wieder eingeschaltet. Es funktioniert wie in Chrome und Firefox wie erwartet, aber in IE 10 & 11 fügt es bei Klicken auf einen Link und definierte vor dem Hash in der URL hinzu, und ich kann nicht herausfinden, warum.
Hier ist mein Skript:

Code: Select all

//initiate scroll spy
$('body').scrollspy({ target: '.spy-active', offset: $offset + 1 });
$('.spy-active').on('activate.bs.scrollspy', function (e) {
if (history.replaceState) {
history.replaceState(null, "", $('a[href*=#]:not([href=#])', e.target).attr("href"));
}
});

//smooth scroll
$('a[href*=#]:not([href=#])').click(function (e) {
e.preventDefault();
//deactivate scrollspy for duration of transition
$('nav').removeClass('spy-active');

//remove active class from all list items
$('li').each(function () {
$(this).removeClass('active');
});
//add active class to clicked item
$(this).parent().addClass('active');
var target = this.hash;
var $target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top - $offset
}, 500, 'swing', function () {
if (history.replaceState) {
history.replaceState(null, "", target);
}
//reactivate scrollspy
$('nav').addClass('spy-active');
});
});

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post