JQuery 对同一项目进行两次动画处理
我通过一个菜单按钮对图像进行一定量的动画处理。它会根据菜单按钮滑出。然后还有另一个链接,单击该链接时图像需要滑出更多。这并没有发生。
这是 jQuery
$(document).ready(function() {
$("#busoptbio").hide();
$("#current").toggle(function() {
$("#busoptbio").show();
$("#busoptbio").animate({
left: '+=348px'
}, 1200);
}, function() {
$("#busoptbiolnk").click(function() {
$("#busoptbio").animate({
left: '+=550px'
}, 1200); < ------2nd animate not working
});
});
});
非常感谢, 安德里亚
I'm animating an image a certain amount from one menu button. It slides out per menu button. Then there's another link that when clicked the image needs to slide out more. This isn't happening.
Here's the jQuery
$(document).ready(function() {
$("#busoptbio").hide();
$("#current").toggle(function() {
$("#busoptbio").show();
$("#busoptbio").animate({
left: '+=348px'
}, 1200);
}, function() {
$("#busoptbiolnk").click(function() {
$("#busoptbio").animate({
left: '+=550px'
}, 1200); < ------2nd animate not working
});
});
});
Thanks so much,
Andrea
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当前您正在使用切换函数,它将两个事件绑定到单个链接,在您的情况下,这是 ID 为
#current
的元素。仅当您单击#current
时才会调用这些事件。您无法监听切换开关内部的点击,因为它本身已经是一个监听器。因此,如果您希望在单击“与专家见面”时出现第二个动画,您需要以不同的方式处理它:
希望这会有所帮助!
编辑
如果您要使用
作为触发器,请确保不定义
href
或防止触发默认事件(转到 href 中的链接)。我已经更新了代码以防止默认操作,但正如之前提到的,这也可以通过更改
来解决
Currently you are using the toggle function which binds two events to a single link, in your case this is the element with the ID
#current
. These events will only be called when you click on#current
. You can't listen for a click inside of the toggle, which is already a listener on its own.So if you want to have the second animation happen when you click "Meet the experts", you'll need to approach it differently:
Hope this helps!
EDIT
If youre gonna use a
<a>
as a trigger, be sure to either not definehref
or prevent the default event from being triggered (going to the link in href).I have updated the code to prevent the default action, but as mentioned before this could also be solved by changing the
<a>
从网站上看,动画效果很好,问题是您的点击事件位于 div 而不是链接上。从:
$("#busoptbiolnk").click
到$("#busoptbiolnk a").click
,以便标签本身接收点击。
在 Chrome 中进行测试,在第二个链接上单击彩色框下方而不是文本。
编辑:
我看到你添加了我的建议,你的问题现在是切换,正如乔伊所说。现在,如果您单击“业务优化服务”,再次单击它,然后单击该链接,它就会切换。删除切换开关并在没有它的情况下绑定事件。
再次编辑:
您的页面在动画播放之前被重定向,将 return false 添加到点击处理程序(如上所述)来修复。或者,将 a#current 的 href 设置为“#”
From looking at the site, the animation works fine, the problem is your click event is on the div rather than the link. Go from:
$("#busoptbiolnk").click
to$("#busoptbiolnk a").click
so that the<a>
tag itself receives the click.Tested in Chrome, on the second link click below the colored box instead of on the text.
EDIT:
I see that you added my suggestion, your problem is now the toggle as Joey says. It now toggles if you click the 'Business Optimization services', click it again, and then click the link. Remove the toggle and just bind the events without it.
EDIT again:
your page gets redirected before the animation plays, add return false to the click handlers (as above) to fix. Alternatively, set a#current's href to "#"