我有一個元素在滾動過某個位置時是固定的,當元素的底部與另一個元素的底部齊平時,我希望元素變爲靜態。使用jquery如何測試元素的底部是否與另一個元素的底部一致?
那麼基本上我該如何測試一個元素的底部是否與平行於該固定元素的元素的底部平齊。
此代碼處理固定元素,我只需要關閉var imgCon = $('#imageContent');
的底部與var txtCon = $('#textContent');
的底部水平。
var imgCon = $('#imageContent');
var txtCon = $('#textContent');
var offset = txtCon.offset();
var txtCon = offset.top - 60;
var txtbottom = $('#textContent').position().top + $('#textContent').outerHeight(true);
if ($(this).scrollTop() >= txtCon) {
imgCon.addClass('fixed');
imgCon.removeClass('floatImage');
var contentWth = $('#postContent').width();
var number = contentWth * 0.35;
imgCon.css('width', number);
$(window).resize(_.debounce(function() {
var contentWth = $('#postContent').width();
var number = contentWth * 0.35;
$('#imageContent').css('width', number);
}, 10));
} else if ($(this).scrollTop() <= txtCon) {
imgCon.removeClass('fixed');
imgCon.addClass('floatImage');
}
//some magic that tests whether bottom is level with parallel container bottom
if (($(this).scrollTop()) >= txtbottom) {
imgCon.removeClass('fixed');
}
啊,這聽起來很有用,我會看一看。 – UzumakiDev