如何在 jQuery 中使动画在一段时间内不活动
这里 jsfiddle 链接到我的问题 http://jsfiddle.net/XnnvD/35/ (不完全是工作)
我会尝试解释问题是什么,我在 jQuery 中有 3 组动画
1-图像在一段时间后反弹并消失,如下所示:
$('#homePageImage').animate(
{ top: '50px' },
{ queue: false, duration: 1000, easing: 'easeOutBounce' });
$('#homePageImage').delay(3000).effect('drop', { direction: "right" });
2-随机设置图像 .fadeIn()
如下:
randNumArray = shuffle(randNumArray);
for (var i = 0; i < 9; i++)
{ $('#fs' + randNumArray[i]).delay(j += 200).fadeIn(j); }
3- 将鼠标悬停在这些图像上,将放大它们,如下所示:
$(function () {
$("ul.thumb li").hover(function () {
$(this).css({ 'z-index': '10' });
$(this).find('img').addClass("hover").stop().animate({
marginTop: '-110px',
marginLeft: '-110px',
top: '50%',
left: '50%',
width: '174px',
height: '174px',
padding: '20px'
}, 500);
}, function () {
$(this).css({ 'z-index': '0' });
$(this).find('img').removeClass("hover").stop().animate({
marginTop: '0',
marginLeft: '0',
top: '0',
left: '0',
width: '100px',
height: '100px',
padding: '5px'
}, 500);
});
});
问题: 如果用户在第一组动画完成之前悬停,则图像不会完全.fadeIn()
,因此部分/不可见
我想要的: 我希望第三组(悬停放大)保持不活动状态,直到我的第一组和第二组动画完成,我该怎么做?
谢谢
here the jsfiddle link to my problem http://jsfiddle.net/XnnvD/35/ (not quite working)
I'll try explaining what the problem is, I have 3 sets of animation in jQuery
1- Image bounces and fades away after some TimePeriod as below:
$('#homePageImage').animate(
{ top: '50px' },
{ queue: false, duration: 1000, easing: 'easeOutBounce' });
$('#homePageImage').delay(3000).effect('drop', { direction: "right" });
2- Set of images .fadeIn()
randomly as below:
randNumArray = shuffle(randNumArray);
for (var i = 0; i < 9; i++)
{ $('#fs' + randNumArray[i]).delay(j += 200).fadeIn(j); }
3- Hovering over these images, will enlarge them as below:
$(function () {
$("ul.thumb li").hover(function () {
$(this).css({ 'z-index': '10' });
$(this).find('img').addClass("hover").stop().animate({
marginTop: '-110px',
marginLeft: '-110px',
top: '50%',
left: '50%',
width: '174px',
height: '174px',
padding: '20px'
}, 500);
}, function () {
$(this).css({ 'z-index': '0' });
$(this).find('img').removeClass("hover").stop().animate({
marginTop: '0',
marginLeft: '0',
top: '0',
left: '0',
width: '100px',
height: '100px',
padding: '5px'
}, 500);
});
});
The Problem:
If the user hovers before the 1st set of animation is complete, the images don't .fadeIn()
completely, and hence are partially/not visible
What I want:
I want the 3rd set (hovering to enlarge) to remain inactive till my 1st and 2nd set of animations are complete, how can I do this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试在第二个动画的后面调用悬停函数作为回调函数吗?基本而言:
Could you try calling the hover function as a callback function on the back of the second animation. In basic terms:
难道你只想使用回调:
Don't you just want to use a callback:
将您的 Hover 函数放入像这样的 SetTimeOut 函数中
,这样可以确保在指定的时间段之前不会发生悬停!
Put your Hover function in a SetTimeOut function like this
So this will ensure that the hover doesn't happen till the specified time period!