zoukankan      html  css  js  c++  java
  • 页面刷新时直接定位到某位置

    方法一:

    $(document).ready(function() {
       window.location.href ="#come here";
    });

    (注:用此方法页面链接后会多一个锚点类名)

    方法二:

    <script>
    var timer, scrollHeight, viewHeight, step = 2000, sTop = 0,isScrict=document.compatMode=='CSS1Compat';
    document.onclick = function () { clearInterval(timer); }
    function Move() {
    //设置滚动前获取当前的的滚动高度和sTop比较,如果小于sTop或者和sTop的差距大于step定义的,说明拖拽过滚动条了
    var nowScrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
    if (nowScrollTop < sTop || (nowScrollTop - top > step)) clearInterval(timer);
    sTop += step;
    document.documentElement.scrollTop = document.body.scrollTop = sTop;
    if (sTop + viewHeight > scrollHeight) {//滚动到底部
    clearInterval(timer);
    document.documentElement.scrollTop = document.body.scrollTop = 700//跳转到顶部
    }
    }
    window.onresize = function () {
    viewHeight = document[isScrict?'documentElement':'body'].clientHeight;
    scrollHeight = document[isScrict?'documentElement':'body'].scrollHeight;
    }
    window.onload = function () {
    window.onresize();
    timer = setInterval(Move, 0);
    }
    </script>

    (虽然不会增加锚点类名,但是在页面元素全部加载完之后跳转到指定位置)

  • 相关阅读:
    thinkPHP 远程数据库和远程连接数据库表名大小写混合
    浏览器兼容性的问题
    input 的那些事
    jquery ui draggable失效的问题
    thinkphp在php5.6以上版本显示"No input file specified"
    ajax dataType
    DOM对象的处理
    ubuntu 16.4 中eth0添加ip地址,且可以上网
    linux 安装phpstudy
    select样式清除
  • 原文地址:https://www.cnblogs.com/liuyingself/p/7837864.html
Copyright © 2011-2022 走看看