js scrollIntoView

来源:互联网 发布:淘宝网天猫商城男装 编辑:程序博客网 时间:2024/05/22 15:03
个人觉得可通过  scrollIntoView()函数实现网页返回顶部的功能;
<html><head>    <title>HTML5_ScrollInToView方法</title>    <meta  charset="utf-8">    <style>        #begin{            width: 100%;            height: 100%;            background: pink;        }        #box{            width: 100%;            height: 800px;            background: #000;            border:1px solid black;        }    </style></head><body><input id="btn2" type="button" value="false" onclick="falseScrollIntroview()"><div id="begin"></div><div id="box"></div><input id="btn1" type="button" value="ture" onclick="trueScrollIntroview()"><script>    var btn1=document.getElementById("btn1");    var btn2=document.getElementById("btn2");    var box=document.getElementById("box");    var begin=document.getElementById("begin");    function trueScrollIntroview() {        begin.scrollIntoView(true);    }    function falseScrollIntroview() {        box.scrollIntoView(false);    }//    var box=document.querySelector("#box");//    box.style.height="300px";</script></body></html>
原创粉丝点击