Home >Web Front-end >JS Tutorial >jQuery implementation of anchor point scoll effect example analysis_jquery

jQuery implementation of anchor point scoll effect example analysis_jquery

WBOY
WBOYOriginal
2016-05-16 16:10:351178browse

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:

Copy code The code 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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn