JSLite - 尺寸位置

2018-12-07 00:36 更新

如有疑問歡迎到這些地方交流,歡迎加入JSLite.io組織團伙共同開發(fā)!

segmentfault社區(qū) | 官方網(wǎng)站 | 官方文檔-更詳細 | Issues

offset

獲得當前元素相對于document的位置。返回一個對象含有:left|top|width|height

$("#box").offset()  //?Object {left: 8, top: 8, width: 1260, height: 0}
$("#box").offset().left  //?  8

width

width() ? number

width(value) ? self

width(function(index, oldWidth){ ... }) ? self

獲取對象象集合中第一個元素的寬,或設置對象集合所有元素的寬。

$("#box").width()   // => 342
$(window).width()   // => 456 (可視區(qū)域?qū)挾?
$(document).width() // => dsf 

height

height() ? number

height(value) ? self

height(function(index, oldWidth){ ... }) ? self

獲取對象象集合中第一個元素的高,或設置對象集合所有元素的高。

$("#box").height()   // => 342
$(window).height()   // => 456 (可視區(qū)域高度)
$(document).height() // => dsf 

scrollLeft

scrollLeft() ? self
獲取匹配的元素集合中第一個元素的當前水平滾動條的位置

$("body").scrollLeft(400);

scrollTop

scrollTop() ? self
獲取匹配的元素集合中第一個元素的當前垂直滾動條的位置

$("body").scrollTop(400);
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號