0
爲.csw-step4-price-summary
格我的默認值是如何在jquery中用css方法設置位置?
.csw-step4-price-summary {
width: 270px;
position: absolute;
display: inline-block;
bottom: 661px;
right: 40px;
}
當我要做到以下幾點,它確實改變位置固定,但它並沒有底部和正確的價值觀反應。
$(document).scroll(function() {
var y = $(this).scrollTop();
if (y > 220) {
$(".csw-step4-price-summary").css({
'position': 'fixed',
'bottom': '661',
'right': '140'
});
} else {
$(".csw-step4-price-summary").css({ 'position': 'absolute'});
}
});
任何建議,爲什麼這可能會發生?提前致謝。
添加 「PX」 在的CSS方法的價值 – mikepa88
你錯過了'px'從位置值。我還建議你通過將這些值放入類中來簡化邏輯,然後根據需要調用toggleClass()。以拼寫錯誤結尾 –
如果'px'是所需的單位,則可以將一個數字作爲值傳遞給'bottom'或'right',jQuery將應用'px'。即「底部」:661。 – hungerstar