我想通过滚动来调整图像大小。但是,问题似乎出在我的职能上。我不能正确使用if条件。
我希望结果像Apple网站一样:https://www.apple.com/iphone-11/
jQuery(window).scroll(function () {
var imageWidth = jQuery("img#big").width();
var stopImage = jQuery("img#big").width(800);
if (imageWidth >= stopImage) {
var s = imageWidth - Math.min(imageWidth, $(document).scrollTop() * 20);
jQuery("img#big").width(s);
}
});
所以我试图重复这个问题。看来您使用的乘数比您需要的值大。
scrollTop()* 0.5或scrollTop()* 2
jQuery(window).scroll(function () {
var imageWidth = jQuery("img#big").width();
var stopImage =800;
if (imageWidth >= stopImage) {
var s = imageWidth - Math.min(imageWidth, $(document).scrollTop() * 0.5);
jQuery("img#big").width(s);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img id="big" src="https://images.pexels.com/photos/1660995/pexels-photo-1660995.jpeg?cs=srgb&dl=orange-lighthouse-1660995.jpg&fm=jpg">
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句