[英]How to toggle between two functions in jquery?
我不明白我的代码有什么问题? 我想在单击时在jQuery中的两个函数之间切换。 谢谢
$(".col-md-3").toggle(
function()
$(this).animate({
left: "-5px",
top:"-5px"
}, 100);,
function()
$(this).animate({
left: "5px",
top:"5px"
}, 100);
);
您的代码格式似乎不正确,例如没有大括号。
你可以试试这个代码吗?
$(".col-md-3").toggle(
function () {
$(this).animate({
left: "-5px",
top: "-5px"
}, 100);
},
function () {
$(this).animate({
left: "5px",
top: "5px"
}, 100);
}
);
您的函数体必须位于{
和}
,这不是可选的,就象您在想的那样,只有一行if
语句是可选的。
$(".col-md-3").toggle(
function(){
$(this).animate({ left: "-5px", top:"-5px" }, 100);
},
function(){
$(this).animate({ left: "5px", top:"5px" }, 100);
}
);
感谢您指出:)这是一个愚蠢的错误。尝试过之后,我意识到这并不是我想要的。 我最初希望对象在“单击”后进行动画处理,并在再次“单击”时进行动画处理回到原始状态。
如果我以:
$('。col-md-3')。on('click',boxMove);
函数boxMove(){
$(this).animate({
left: "-5px",
top:"-5px"
}, 100);
};
它仅以一种方式进行动画处理。 我如何添加函数(如果(已)已设置动画),则应向左移动“ 5px”,向左移动“ 5px”以返回到原始(未激活)状态?
提前非常感谢您!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.