codecamp

JSLite - 尺寸位置

如有疑问欢迎到这些地方交流,欢迎加入JSLite.io组织团伙共同开发!

segmentfault社区 | 官方网站 | 官方文档-更详细 | 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 (可视区域宽度)
$(document).width() // => dsf 

height

height() ⇒ number

height(value) ⇒ self

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

获取对象象集合中第一个元素的高,或设置对象集合所有元素的高。

$("#box").height()   // => 342
$(window).height()   // => 456 (可视区域高度)
$(document).height() // => dsf 

scrollLeft

scrollLeft() ⇒ self
获取匹配的元素集合中第一个元素的当前水平滚动条的位置

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

scrollTop

scrollTop() ⇒ self
获取匹配的元素集合中第一个元素的当前垂直滚动条的位置

$("body").scrollTop(400);
JSLite - 效果
JSLite - 过滤
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }