当前位置:网站首页>JS window object

JS window object

2022-06-09 08:46:00 Calf (ox)

One 、screen attribute

window.screen Object contains information about the user screen

screen.availWidth Screen width

screen.availHeight   Screen height

Two 、history object

forward() Method to load the next page in the history list

back() Method to load the previous page in the history list ( If there is )

go( Parameters ) Method to load a specific page in the history list

Parameters can be numbers , Use the page you want to visit in History Relative position in the page list of .

        go(0) Refresh this page

        go(1) Go to a page

        go(-1) Go back to the previous page

3、 ... and 、location object

location.href         Return the address of the current page

location.pathname         Pathname

location.reload()         Reload Refresh this page

3、 ... and 、 navigator

window.navigator Object contains information about the visitor's browser .

Four 、open()

Open a new browser window , Load given URL Specified document

window.open(

        "http://www.baidu.com",

        "_blank",

        "width=500,height=500"

      );// Open a new window , Width 200px, Height 500px 

window.close(); // close

5、 ... and 、 event

window.onload = function () {};
  wait until html Document loaded ( Including pictures, etc. after downloading ) after , Will trigger onload event

window.onresize = function () {
      console.log(" The window size has changed ");
    };
  When the window size changes , Will trigger onresize event

window.onscroll = function () {
      console.log(" Your browser scroll bar scrolled ");
    };
  When the scroll bar scrolls, it triggers onscroll event

6、 ... and 、 Back to the top

var _gotop = document.getElementById("gotop");
    var timer = null,
      sTop;
    _gotop.onclick = function () {
      timer = setInterval(function () {
        document.documentElement.scrollTop -= 10;
        sTop = document.documentElement.scrollTop;
        if (sTop <= 0) {
          clearInterval(timer);
        }
        // console.log(sTop);
      }, 100);
    };

原网站

版权声明
本文为[Calf (ox)]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206090820102949.html