首页 > 其他 > 详细

锚点跳转滑动效果

时间:2015-11-27 17:12:13      阅读:269      评论:0      收藏:0      [点我收藏+]

普通的锚点想必大家都知道,点击的时候就会跳转到页面指定的位置,但是没有过渡效果。

在页面调用下面这个js之后,页面的锚点就会有过渡效果了。

//锚点跳转滑动效果
$(‘a[href*=#],area[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
            }, 1000);
            return false;
        }
    }
});

 

锚点跳转滑动效果

原文:http://www.cnblogs.com/h-change/p/5000745.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!