gpt4 book ai didi

javascript - jQuery - 第二次点击时的不同功能

转载 作者:行者123 更新时间:2023-11-30 08:41:58 24 4
gpt4 key购买 nike

我正在尝试创建窗帘打开和关闭效果。但出于某种原因,我的窗帘一旦打开就无法关闭。

这是我目前拥有的: http://jsfiddle.net/ssc3z1tf/

我尝试了很多不同的方法,添加和删除类,切换类,在这里我使用了 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');
}
});
});

任何帮助都会很棒!我迷路了!谢谢!!

最佳答案

改变

if ($('.curtain').attr('rel', 'open')){

if ($('.curtain').attr('rel') == 'open') {

对第二个 if 语句做同样的事情。 .attr(name, value) 总是将属性设置为指定的值,而 .attr(name) 只会返回值

Updated Fiddle

关于javascript - jQuery - 第二次点击时的不同功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25491274/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com