jQuery 全屏背景在菜单上移动
我目前正在构建一个全屏画廊 WP 主题,我注意到,当您尝试选择图像来查看背景并用鼠标上下滚动时,只要已选择图像,这就可以工作,但我我正在尝试创建一个无滚动区域(图像菜单),以便当您选择新图像来查看背景时,它不会跳来跳去。
这是我的 global.js
。我注意到,如果我添加 return false;
它会停止滚动,但我丢失了图像更改,因此我将其删除。
$(document).ready(function() {
$(".dropgallery a, #fp_thumbtoggle").removeAttr("title");
$('#fp_thumbtoggle, .dropgallery img').click(function() {
$('#fp_thumbtoggle').toggleClass("active");
if ($('#fp_thumbtoggle').hasClass('active')){
$('#fp_thumbtoggle').animate({top:'65px'});
}else{
$('#fp_thumbtoggle').animate({top:'185px'});
}
$('.dropgallery').slideToggle('500');
return false;
});
});
您可以找到我的 gallery.js
这里。
I'm currently building a Full-Screen gallery WP theme and I've noticed that when you try to select an image to view the background and scroll up and down with the mouse, this works as long as the image has been selected but I'm trying to make a scroll-free area (image menu) so that when you select a new image to view the background it doesn't jump around.
This is my global.js
. I notice that if I add the return false;
it stops scrolling but I lost the image change so i removed it.
$(document).ready(function() {
$(".dropgallery a, #fp_thumbtoggle").removeAttr("title");
$('#fp_thumbtoggle, .dropgallery img').click(function() {
$('#fp_thumbtoggle').toggleClass("active");
if ($('#fp_thumbtoggle').hasClass('active')){
$('#fp_thumbtoggle').animate({top:'65px'});
}else{
$('#fp_thumbtoggle').animate({top:'185px'});
}
$('.dropgallery').slideToggle('500');
return false;
});
});
You can find my gallery.js
here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TL;DR
说明:
事件处理程序(无论是 jQuery 还是原始 JavaScript)采用单个参数,即事件。这些事件对象包含各种有趣的东西,使它们变得有用,但其中许多东西因浏览器而异。幸运的是 stopPropagation 是通用的。
对于您的用例,您可能会遇到事件在堆栈中冒泡的问题。假设您有这样的内容:
该事件将首先在底部 div 上触发,然后一旦执行完成,它将冒泡。每个侦听器都会收到通知,直到没有更多侦听器为止。
为了阻止这种冒泡,JavaScript(不是 jQuery)为我们提供了该事件对象的
stopPropagation
方法。调用此函数将告诉浏览器取消冒泡过程。TL;DR
Explanation:
Event handlers (whether jQuery or raw JavaScript) take a single parameter, an event. These event objects have all sorts of nifty things in them that make them useful, but many of these vary by browser. Fortunately stopPropagation is universal.
For your use case, you're probably having problems with the events bubbling up the stack. Say you have something like this:
The event will be fired first on the bottom div, then once that execution has completed, it will bubble up. Each listener will get the notification until there are no more listeners.
In order to stop this bubbling, JavaScript (not jQuery) has given us a
stopPropagation
method on that event object. Calling this will tell the browser to cancel the bubble process.