[英]vertical offset for element
I have this code 我有这个代码
<div style="height:[Variable]px"></div>
<!--
or [ one or several div and section , with variable height ]
-->
<div class="Element" style="Position:relative">
<div class="Pin"></div>
</div>
I need to get vertical offset for $('.pin')
object , from top of my web page 我需要从我的网页顶部获取
$('.pin')
对象的垂直偏移量
So what would u guys suggest me ? 那么你们会建议我什么呢?
Compare the offset of the ".pin" tag element to how far down the page the user has scrolled. 将“ .pin”标签元素的偏移量与用户滚动的页面进行比较。 The $(window).scroll() function will get you the amount the user has scrolled down so:
$(window).scroll()函数将为您提供用户向下滚动的数量,因此:
$(".select").click(function() {
var pin = $('.pin');
var top = offset.top;
var bottom = $(window).height() - top - pin.height();
bottom = bottom - offset.top;
});
i hope its help 我希望它的帮助
var Pin_Offset $('.pin').offset().top
or for variable div object 或用于div变量对象
$(window).scroll(function(){
var Pin_Offset = $('.pin').offset().top + $(window).scrollTop()
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.