首页    >    新闻资讯    >   wordpress迅速回顶技巧

wordpress迅速回顶技巧

很多博主都会遇到这个情况,有时候wordpress里的文章偏长,阅读到文章末尾的时候需要滑动鼠标才能回到文章顶部,这样就会比较麻烦。笔者在此分享一段双击空白处就能迅速回到文章顶部的代码,记得把JS代码放到当前主题的头文件header.php中。

<script type="text/javascript">
$(function(){
    var scrollTo = function(top, duration, callback) {
        var w = $(window);
        var FPS = 50;
        var currentTop = w.scrollTop();
        var offset = (currentTop – top) / (duration * FPS / 1000);
        var n = 0;
        var prevTop = currentTop;
        var t = setInterval(function() {
            if ((prevTop – top) * (currentTop – top) <= 0) {
                clearInterval(t);
                currentTop = prevTop = top;
                w.scrollTop(top);
                if (callback) callback();
            } else {
                prevTop = currentTop;
                w.scrollTop(currentTop -= offset);
            }
        }, 1000 / FPS);
    }
    $('body').dblclick(function(){
        scrollTo(0, 200, function(){
        });
        $(".textField,#commentForm textarea").focus();
    });
    $('#container.#footer').dblclick(function(e){e.stopPropagation();});
});
</script>

分类:新闻资讯

标签:, , ,

* 版权声明:作者WordPress啦! 转载请注明出处。