美文网首页
.offset(), .position(), .scrollT

.offset(), .position(), .scrollT

作者: 这里王工头 | 来源:发表于2019-01-30 01:54 被阅读0次

    欢迎访问我的博客https://qqqww.com/,祝码农同胞们早日走上人生巅峰,迎娶白富美~~~

    上篇文档总结了《一些坐标属性》,这里总结一些距离或者宽高属性,它们分别为:
    .offset()
    .position()
    .scrollTop(),.scrollLeft
    .width(),.height
    .innerWidth(),innerHeight()
    .outerWidth(),outerHeight()

    .offset()

    .offset().top:元素距离文档上边的距离
    .offset().left:元素距离文档左边的距离
    当然也可以自己设置

    xxx.offset({
        left: 10,
        top: 10
    })
    

    .position()

    .position().top 和 .position().left: 与被定位的祖先元素的偏移距离

    1. 若父元素被定位了,则就是离父元素的偏移距离
    2. 反之,网上辈祖先找,如果没有祖先被定位,一般是相对于 body 偏移距离

    .scrollTop(),.scrollLeft

    滚动条滚动被卷去的距离:
    .scrollTop():滚动条卷去的垂直距离
    .scrollLeft():滚动条卷去的水平距离

    .width(),.height

    元素的宽度,不包含padding,border,margin,且支持写操作,例如$test.width(100)

    .innerWidth(),innerHeight()

    元素的宽度,包含padding,不包含bordermargin,且支持写操作,例如$test.innerWidth(100)

    .outerWidth(),outerHeight()

    1. 元素的宽度,包含paddingborder,不包含margin
    2. .outerWidth(true),此时连margin一块都包括了

    相关文章

      网友评论

          本文标题:.offset(), .position(), .scrollT

          本文链接:https://www.haomeiwen.com/subject/oxqqsqtx.html