首页 > Web开发 > 详细

JQuery 实现锚点链接之间的平滑滚动

时间:2016-03-11 16:50:29      阅读:265      评论:0      收藏:0      [点我收藏+]

24. 解决链接锚点的生硬问题

 $(‘.nav .btn[href*=#],.icon2,.icon3‘).click(function() {
        if (location.pathname.replace(/^\//, ‘‘) == this.pathname.replace(/^\//, ‘‘) && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $(‘[id=‘ + this.hash.slice(1) + ‘]‘);
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $(‘html,body‘).animate({
                    scrollTop: targetOffset
                },
                1000);
                return false;
            }
        }
  })

JQuery 实现锚点链接之间的平滑滚动

原文:http://www.cnblogs.com/duowen/p/5266298.html

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