jQuery-第二次单击具有不同的功能 [英] jQuery - Different function on second click
本文介绍了jQuery-第二次单击具有不同的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个帷幕.关闭效果.但是由于某种原因,我一旦打开窗帘就无法将其关闭.
I'm trying to create a curtain Opening & Closing effect. But for some reason I can't make my curtains close once they're opened.
这是我到目前为止所拥有的: http://jsfiddle.net/ssc3z1tf/
我尝试了很多不同的方法,添加和删除类,切换类,在这里我使用了rels.
I've tried quite a few different ways, adding and removing classes, toggling classes and here I've used rels.
$(document).ready(function () {
$('.curtain').click(function(){
if ($('.curtain').attr('rel', 'open')){
$('.curtainLeft').animate({"left":"-400px"}, "slow");
$('.curtainRight').animate({"right":"-400px"}, "slow");
$('.curtain').attr('rel', 'closed');
} else if ($('.curtain').attr('rel', 'closed')){
$('.curtainLeft').animate({"left":"-0px"}, "slow");
$('.curtainRight').animate({"right":"-0px"}, "slow");
$('.curtain').attr('rel', 'open');
}
});
});
任何帮助都会很棒!我迷路了!谢谢!
Any help would be great! I'm lost! Thanks!!
推荐答案
更改
if ($('.curtain').attr('rel', 'open')){
到
if ($('.curtain').attr('rel') == 'open') {
对第二个if语句执行相同的操作. .attr(name, value)
将始终将属性设置为指定的值,而.attr(name)
将仅返回值
And do the same for the second if statement. The .attr(name, value)
will always set the attribute to the specified value, whereas .attr(name)
will simply return the value
这篇关于jQuery-第二次单击具有不同的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文