鼠标悬停并悬停意图
我使用鼠标悬停来更改 jQuery Supersized 插件上的幻灯片编号,具体取决于您滑过哪个按钮。
但是,如果在滚动到另一个按钮之前尚未完成下一张幻灯片的淡入淡出动画,则不会更改幻灯片。
有没有办法每隔几毫秒重新检查一次鼠标是否仍在按钮上并加载幻灯片(如果尚未加载)?
另外,如果鼠标在一定时间内没有悬停在任何按钮上,我想加载不同的幻灯片。如何堆叠事件,以便鼠标移出引用所有按钮并添加时间事件?
到目前为止我的代码(鼠标悬停当前仅适用于最后一个按钮):
$(".mybutton1").mouseover(function() {
api.goTo(2);
});
$(".mybutton2").mouseover(function() {
api.goTo(3);
});
$(".mybutton3").mouseover(function() {
api.goTo(4);
}).mouseout(function(){
api.goTo(1);
});
提前致谢!
。
====================更新======================
非常感谢您的最新更新。不幸的是我无法让你的代码工作。但是,我想我可能已经找到了一个更简单的解决方案,修改您的原始代码并使用 jQuery hideIntent...
我发现我可以禁用 Supersized 来阻止动画期间幻灯片的更改,并且我可以使用 hooverIntent 来确保它在更改之前等待足够的时间滑动以使动画不会堆叠起来。
以下代码可以完美地更改鼠标悬停时的幻灯片。
但我无法让 mouseout 工作,因为它为每个按钮创建一个新实例,并且当鼠标从一个按钮滚到下一个按钮时,它会堆叠动画。此外,似乎只有鼠标移出的延迟计时器,而不是像鼠标悬停那样的间隔选项。
所以我只需要稍微修改一下,这样:
如果鼠标没有在任何按钮上停留 1000 毫秒,则 api.goTo(1);
我能想到的唯一方法是创建一个浏览器窗口整个大小的不可见链接,并运行第二个hoverIntent函数以在滚动到此时更改幻灯片,但我认为这不是最好的方法!
谢谢
var buttonNumber = <?php echo $project_count; ?>; //Change this number to the number of buttons.
var prefix = "#project-link";
var prefix2 = "#project-bullet";
for(var i=0; i<buttonNumber; i++){
(function(i){ //Anonymous function wrapper is needed to scope variable `i`
var id = prefix+i;
$(id).hoverIntent({
interval: 350,
over: mouseyover,
timeout: 1000,
out: mouseyout
});
function mouseyover(){
api.goTo(i+2);
$(".project-bullet").fadeOut(1);
$(prefix2+i).fadeIn(1000);
}
function mouseyout(){
//api.goTo(1);
}
})(i);
}
I'm using mouseover to change the slide number on the jQuery Supersized plugin depending on which button you rollover.
However, if the fade animation to the next slide hasn't completed before rolling over another button, it doesn't change the slide.
Is there a way to re-check every few milliseconds whether the mouse is still over the button and load the slide if it hasn't been loaded already?
Also I'd like to load a different slide if the mouse hasn't been over any of buttons for a certain amount of time. How can I stack up the events so the mouseout refers to all of the buttons and also add a time event?
My code so far (mouseout currently only applies to the last button):
$(".mybutton1").mouseover(function() {
api.goTo(2);
});
$(".mybutton2").mouseover(function() {
api.goTo(3);
});
$(".mybutton3").mouseover(function() {
api.goTo(4);
}).mouseout(function(){
api.goTo(1);
});
Thanks in advance!
.
=====================UPDATE=====================
Thanks very much for your latest update. Unfortunately I couldn't get your code to work. However, I think I may have found an simpler solution modifying your original code and using jQuery hoverIntent…
I found out I could disable Supersized from stopping the slides changing during the animation and I can use hoverIntent to ensure that it waits enough time before changing the slide so the animations don't stack up.
The following code works perfectly changing slides on mouseover.
But I can't get mouseout to work because it's creating a new instance of it for each button, and it stacks up the animations when the mouse rolls out of one button and onto the next. Also there only seems to be a delayed timer for the mouseout and not an interval option like the mouseover.
So I just need to modify this slightly so that:
If the mouse is not over ANY of the buttons for 1000 ms, then api.goTo(1);
The only way I can think of would be to create an invisible link the entire size of the browser window and run a second hoverIntent function to change the slide when it rolls over this, but I don't think that would be the best way!
Thanks
var buttonNumber = <?php echo $project_count; ?>; //Change this number to the number of buttons.
var prefix = "#project-link";
var prefix2 = "#project-bullet";
for(var i=0; i<buttonNumber; i++){
(function(i){ //Anonymous function wrapper is needed to scope variable `i`
var id = prefix+i;
$(id).hoverIntent({
interval: 350,
over: mouseyover,
timeout: 1000,
out: mouseyout
});
function mouseyover(){
api.goTo(i+2);
$(".project-bullet").fadeOut(1);
$(prefix2+i).fadeIn(1000);
}
function mouseyout(){
//api.goTo(1);
}
})(i);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新答案(2011 年 10 月 9 日):
修订:
var goToApiOne = false; //新增:Api 1的“内存”
mouseyover
,第一行:goToApiOne = false; //取消对 Api 1 的任何移动
mouseyout
:见下文,整个函数已被替换此代码背后的概念:
(goToApiOne = false)
goToApiOne = true
+setTimeout
并延迟 1000 毫秒setTimeout
调用函数:IfgoToApiOne == true
THENgotoApi(1);
andgoToApiOne = false
代码>(重置)。Old answer (28 sept 2011):
我已经更改了您的代码,以便您可以轻松地将效果应用于多个按钮,而无需复制粘贴函数的内容。
阅读下面代码中的注释,并根据您的意愿调整代码。在淡入淡出函数和按钮事件处理程序的范围内包含
fadeFinished
变量非常重要。另请注意:我建议将
.projectlink
更改为#projectLink
,因为该元素应该只出现一次。预期行为:
#projectlink2
上:转到幻灯片 4(第一次,无延迟)#projectlink1
上(500 毫秒内) 中止“幻灯片 1 请求”。启动幻灯片 3# projectlink3
:前面的(参见3)动画尚未完成。立即请求“幻灯片 5”新功能一次只会运行一张幻灯片。如果您想查看多个(排队的)幻灯片的代码,请参阅修订历史记录。
Updated answer (9 oct 2011):
Revisions:
var goToApiOne = false; //New: the "memory" of Api 1
mouseyover
, first line:goToApiOne = false; //Cancel any move to Api 1
mouseyout
: See below, the whole function has been replacedThe concept behind this code:
(goToApiOne = false)
goToApiOne = true
+setTimeout
with a delay of 1000mssetTimeout
: IfgoToApiOne == true
THENgotoApi(1);
andgoToApiOne = false
(reset).Old answer (28 sept 2011):
I have changed your code, so that you can easily apply effects to multiple buttons without having to copy-paste the contents of the function.
Read the comments in the code below, and adjust the code to your wishes. It's important to have the
fadeFinished
variable in the scope of your fade function, and the button event handler.Another note: I recommend changing
.projectlink
to#projectLink
, because the element should only occur once.Expected behaviour:
#projectlink2
: Go to slide 4 (first time, no delay)#projectlink1
(within 500ms) Aborts "slide 1 request". Initiates slide 3#projectlink3
: The previous (see 3) animation has not finished yet. "Slide 5" is requested without a delayThe new function will only run one slide a time. If you want to see the code for multiple (queued) slides, see the revision history.