js獲取屏幕大小,元素top值等等


<script>
function a(){
document.write(
"屏幕分辨率為:"+screen.width+"*"+screen.height
+"<br />"+
"屏幕可用大小:"+screen.availWidth+"*"+screen.availHeight
+"<br />"+
"網頁可見區域寬:"+document.body.clientWidth
+"<br />"+
"網頁可見區域高:"+document.body.clientHeight
+"<br />"+
"網頁可見區域寬(包括邊線的寬):"+document.body.offsetWidth
+"<br />"+
"網頁可見區域高(包括邊線的寬):"+document.body.offsetHeight
+"<br />"+
"網頁正文全文寬:"+document.body.scrollWidth
+"<br />"+
"網頁正文全文高:"+document.body.scrollHeight
+"<br />"+
"網頁被卷去的高:"+document.body.scrollTop
+"<br />"+
"網頁被卷去的左:"+document.body.scrollLeft
+"<br />"+
"網頁正文部分上:"+window.screenTop
+"<br />"+
"網頁正文部分左:"+window.screenLeft
+"<br />"+
"屏幕分辨率的高:"+window.screen.height
+"<br />"+
"屏幕分辨率的寬:"+window.screen.width
+"<br />"+
"屏幕可用工作區高度:"+window.screen.availHeight
+"<br />"+
"屏幕可用工作區寬度:"+window.screen.availWidth
);
}

js獲取元素到瀏覽器頂部距離:

Element.offsetTop

js獲取元素到瀏覽器左側距離:

Element.offsetLeft

jq獲取和設置元素到瀏覽器頂部距離:

$(Element).offset().top

$(Element).offset({top:number})

移動端獲取頁面的X,Y坐標

        var Div = document.getElementById("BODY");
        Div.ontouchstart = function(e){
            var touch = e.touches[0];
            //clientX,clientY獲取當前觸控點的坐標,
            var x = touch.clientX;
            var y = touch.clientY; 
           //pageX,pageY獲取頁面的X,Y坐標
            var pageX = touch.pageX
            var pageY = touch.pageY   
             
        }    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM