Home > Web Front-end > JS Tutorial > body text

How to get the value of the scroll bar by encapsulating scroll.js

不言
Release: 2018-07-14 15:38:17
Original
1495 people have browsed it

This article mainly introduces how to obtain the value of the scroll bar by encapsulating scroll.js. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

function Obj(){}

Obj.prototype={
 
    scroll:function(){

     /*
      主要是做兼容处理
    
     这里必须时!=null 因为默认值和每次滚动的时侯  都可以值为0
     但是 if(0)为假  所以就只要不为null 就执行
                                                              */
     if(window.pageYOffset!=null){
         /*IE9 和其他标准浏览器*/
   return  {
       left:window.pageXOffset,
       top:window.pageYOffset
   }
   

   }
    /*声明了<!DOCTYPE html> */
  else if(document.compatMode=="CSS1Compat")
{

  return{
       left:document.documentElement.scrollLeft,
       top:document.documentElement.scrollTop

    }  

 }

else{

   return {
      left:document.body.scrollLeft,
      top:document.body.scrollTop

    }    

}


   }

}var obj=new Obj();
Copy after login

The above is The entire content of this article is hoped to be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to solve the problem of non-negative integers when the for in object in Vue

Through node.js Call baidu-aip-SDK to realize the function of ID card recognition

The above is the detailed content of How to get the value of the scroll bar by encapsulating scroll.js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template