jquery 尺寸位置(height/width/offset/scrollTop/scrollLeft)
2017-03-04 15:55
567 查看
尺寸位置
1.高度和宽度操作高度操作height()
作用:设置或获取匹配元素的高度值
//带参数表示设置高度 $(selector).height(200); //不带参数获取高度 $(selector).height();
宽度操作width()
作用:设置或获取匹配元素的宽度值
//带参数表示设置宽度 //不带参数获取宽度 $(selector).width(200);
css()获取高度和height获取高度的区别?
$("div").css("height");//string类型
$("div").height();//number类型 便于参与运算
2.坐标值操作
offset()
作用:获取或设置元素相对于文档左上角的位置
//无参数表示获取,返回值为:{left:num, top:num},值是相对于document的位置 $(selector).offset(); //有参数表示设置,参数推荐使用数值类型 $(selector).offset({left:100, top: 150});
注:设置offset后,如果元素没有定位(默认值:static),则被修改为relative
scrollTop()
作用:获取或者设置元素垂直方向滚动的位置
// 无参数表示获取偏移 $(selector).scrollTop(); // 有参数表示设置偏移,参数为数值类型 $(selector).scrollTop(100);
scrollLeft()
作用:获取或者设置元素水平方向滚动的位置
$(selector).scrollLeft(100);
相关文章推荐
- javascript获得元素的尺寸和位置二 : clientWidth/Height、scrollWidth/Height、scrollTop/Left
- javascript获得元素的尺寸和位置一 : offsetTop/Left、offsetWidth/Height、offsetParent
- CSS专题(二):元素大小与位置offsetLeft offsetTop offsetWidth offsetHeight clientWidth clientHeight scrollWidth s
- javascript获得元素的尺寸和位置一 : offsetTop/Left、offsetWidth/Height、offsetParent
- :元素大小与位置offsetLeft offsetTop offsetWidth offsetHeight clientWidth clientHeight scrollWidth scrollHei
- javascript获得元素的尺寸和位置二 : clientWidth/Height、scrollWidth/Height、scrollTop/Left
- javascript获得元素的尺寸和位置一 : offsetTop/Left、offsetWidth/Height、offsetParent
- CSS专题(二):元素大小与位置offsetLeft offsetTop offsetWidth offsetHeight clientWidth clientHeight scrollWidth s
- DOM元素的各种尺寸offsetHeight/Width,clientHeight/clientWidth,offsetLeft/Top,
- scrollWidth,offsetWidth,clientWidth,width;scrollHeight,offsetHeight,clientHeight,height;offsetTop,scrollTop,top;offsetLeft,scrol
- 区分概念:clientWidth/clientHeight/offsetWidth/offsetHeight/scrollLeft/scrollTop/scrollHeight/scrollWidth
- client/scroll/offset width/height/top/left ---记第一篇博客
- DOM中的scrollWidth(Height/Left/Top),offsetWidth(Height/Left/Top)以及clientWidth(Height/Left/Top)
- HTML中常见的各种位置距离(clientTop clientLeft clientWidth ClientHeight offsetleft offsettop offsetwidth offset
- 深刻了解offsetTop,offsetLeft,offsetWidth,offsetHeight,scrollTop,scrollLeft,scrollWidth,scrollHeight,clientHeight,clientWidth
- offsetTop、offsetLeft、offsetWidth、offsetHeight,scrollTop、scrollLeft、scrollWidth、scrollHeight ,clientHeight、offsetHeight
- offsetTop.offsetLeft,offsetWidth,offsetHeight,offsetParent,scrollTop,scrollLeft,scrollWidth,scrollHeight区别
- offsetWidth clientWidth scrollWidth scrollTop scrollLeft等属性的细微区别
- scrollTOP scrollLeft clientHeight clientWidth 的各浏览器版修正
- offsetTop、offsetLeft、offsetWidth、offsetHeight http://www.cftea.com/c/2006/12/PCTKER6T0V62S854.asp