我不太了解Javascript。 id为“theFixed”的div标签一次只能使用一个javascript行(max vs min,但我需要同时工作。这是我现在的代码。我怎么把“max”和“min”行合而为一。
<script>
$(window).scroll(function(){
$("#theFixed").css("top",Math.max(0,1500-$(this).scrollTop()));
$("#theFixed").css("top",Math.min(0,3000-$(this).scrollTop()));
});
</script>
<div id="theFixed" style="position:fixed;top:2px;bottom:2px;">
<img src="../images/90s/rooms/90s%20room_full_color.png">
</div>`
将两者都移到一个作业中:
$(window).scroll(function(){
$("#theFixed").css(
"top",
Math.min(
Math.max(0, 1500 - $(this).scrollTop()),
3000 - $(this).scrollTop()
)
);
});