jquery a标签的锚点点击的时候页面上缓慢滚动

a标签增加一个名字触发效果:

$(".transition").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},800);
return false;
}
}
});

注意!!!,必须保证a标签的正常的使用

猜你喜欢

转载自www.cnblogs.com/zjhuanjing/p/10383792.html