The example in this article describes how jQuery implements the anchor scoll effect. Share it with everyone for your reference. The specific implementation method is as follows:
$('a[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) {
var targetOffset = $target.offset().top;
var obj = document.documentElement;
If (jQuery.browser.safari)
obj = document.body
If (jQuery.browser.msie)
obj = 'html';
$(obj).animate({scrollTop: targetOffset}, 1000);
return false;
}
}
});
I hope this article will be helpful to everyone’s jQuery programming.