Home  >  Article  >  Web Front-end  >  How jquery implements smooth scrolling between anchor links_jquery

How jquery implements smooth scrolling between anchor links_jquery

WBOY
WBOYOriginal
2016-05-16 17:11:051287browse
复制代码 代码如下:

$('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;
$('html,body').animate({
scrollTop: targetOffset
},
500);
return false;
}
}
});
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