gpt4 book ai didi

javascript - 在 CTRL+MOUSEWHEEL 事件上

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:07:32 24 4
gpt4 key购买 nike

我被要求为我们的页面站点实现 ctrl+mousewheel 事件,以便在用户放大或缩小时更改图像偏移。我找到了这个旧答案 Override browsers CTRL+(WHEEL)SCROLL with javascript我也试过这样做。我下载了 jQuery Mouse Wheel Plugin用于实现,这是我的代码:

var isCtrl = false;  
$(document).on('keydown keyup', function(e) {
if (e.which === 17) {
isCtrl = e.type === 'keydown' ? true : false;
}
}).on('mousewheel', function(e, delta) { // `delta` will be the distance that the page would have scrolled;
// might be useful for increasing the SVG size, might not
if (isCtrl) {
e.preventDefault();
alert('wheel');
}
});

事件单独运行良好,但如果我按住 CTRL 按钮并滚动鼠标,则不会触发滚轮事件。有没有人对此有更好的解决方案,或者我做错了什么?

最佳答案

Fiddle , 为了让它工作,你必须在尝试之前先点击 result 框。

$(window).bind('mousewheel DOMMouseScroll', function(event) 
{
if(event.ctrlKey == true)
{
event.preventDefault();
if(event.originalEvent.detail > 0) {
console.log('Down');
}else {
console.log('Up');
}
}
});

关于javascript - 在 CTRL+MOUSEWHEEL 事件上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33083484/

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