jQuery切换不断重复 [英] jQuery toggle keeps repeating
问题描述
我对jQuery很陌生,但是似乎很容易.一样,我不知道. 我正在尝试在两个动画功能之间切换,但是当两个功能完成时,它会继续进行并同时调用一个功能.
I'm pretty new to jQuery, but seemed like it's a no-brainer. Just the same, I can't figure it out. I'm trying to toggle between two animation functions, but when function two completes, it goes ahead and calls function one as well.
function toggleThis(){
$("#navSliderArrow").toggle(function() {
$(this).animate({ marginLeft: '235' }, 500);
$("#sliderArrow").attr("src", "images/hide_nav.gif");
}, function() {
$(this).animate({ marginLeft: '0' }, 500);
$("#sliderArrow").attr("src", "images/show_nav.gif");
});
}
我做错了什么? 〜gyz
What am I doing wrong? ~gyz
推荐答案
从我之前的评论开始,
据我所知,.toggle只有一个回调函数.没有把握 当您有两个这样的功能时会发生什么. 您想在这里实现吗?
As far as I know, .toggle has only one callback function. Not sure what happens when you have 2 functions like that.. Anyways, What are you trying to achive here?
了解更多信息 .toggle API文档
我假设您正在尝试显示和隐藏#sliderArrow
的onclick
.如果是这样,请尝试以下操作,
I assume that you are trying to show and hide onclick
of #sliderArrow
. If so then try below,
$(function () {
var $slideArrow = $("#sliderArrow");
var $navSlideArrow = $('#navSliderArrow');
$slideArrow.on ('click', function () {
if ($slideArrow.attr('src').indexOf('show') >= 0) {
$navSlideArrow.animate({ marginLeft: '235' }, 500);
$slideArrow.attr("src", "images/hide_nav.gif");
} else {
$navSlideArrow.animate({ marginLeft: '0' }, 500);
$slideArrow.attr("src", "images/show_nav.gif");
}
});
});
这篇关于jQuery切换不断重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!