gpt4 book ai didi

javascript - 通过滚动事件放大/缩小图片

转载 作者:行者123 更新时间:2023-11-28 18:31:32 26 4
gpt4 key购买 nike

当我滚动图片时,我需要放大/缩小图片。我只是问你如何检测图片的滚动进/出?我正在尝试这个(我在互联网上找到了它):

$('.map').scroll(function(event){
if(event.originalEvent.wheelDelta /120 > 0) {
alert('scrolling up !');
}
else{
alert('scrolling down !');
}
});

//

 .map 

是我的图片的类别。

这对我不起作用......

最佳答案

Attach mousewheel event as scroll event is sent whenever the element's scroll position changes.

$('#map').on('mousewheel', function(e) {
e.preventDefault();
if (e.originalEvent.wheelDelta / 120 > 0) {
console.log('scrolling up !', 'X: ', e.pageX, 'Y: ', e.pageY);
} else {
console.log('scrolling down !', 'X: ', e.pageX, 'Y: ', e.pageY);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<img src="https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xft1/v/t1.0-1/p200x200/13096358_986500121418450_5109646388299684610_n.jpg?oh=27ee2801d2df5c9426eef38bb8a45509&oe=57DF3F79&__gda__=1474329392_83b88030c94ec8611160c14161311db5" id="map">
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

关于javascript - 通过滚动事件放大/缩小图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37909784/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com