2015-07-11 113 views
1

抵消我有這樣的代碼垂直的元素

<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> 

enter image description here

我需要垂直於$('.pin')對象偏移,從我的網頁的頂部

那麼將u人建議我?

回答

0
var Pin_Offset $('.pin').offset().top 

或 變量的div對象

$(window).scroll(function(){ 

var Pin_Offset = $('.pin').offset().top + $(window).scrollTop() 

}); 
0

比較「.pin」標記元素的偏移量與用戶滾動頁面的距離。該$(窗口).scroll()函數將讓你的用戶已經向下滾動因此用量:

$(".select").click(function() { 
    var pin = $('.pin'); 
    var top = offset.top; 
    var bottom = $(window).height() - top - pin.height(); 
    bottom = bottom - offset.top; 

}); 

我希望它的幫助