gpt4 book ai didi

javascript - 脚本不进入else语句

转载 作者:行者123 更新时间:2023-11-29 19:35:12 24 4
gpt4 key购买 nike

我的页面右侧有一个表格(id="efficacia")。我写了这个 JS 脚本来左/右点击它

JavaScript

$("#efficacia").click(function() {
var posizione = $("#efficacia").position();

if(posizione.right != 0) {
$(this).animate({
right: '0'
}, 1000);
} else {
$(this).animate({
right: '-202'
}, 1000);
}
});

CSS

#efficacia {
position: fixed;
right: -202px;
top: 200px;
cursor: pointer;
z-index: 100;
}

我的脚本在第一次“点击”时运行良好,然后当我再次点击时它不会在 202px 的右侧移动。看起来那个函数没有进入else statemet。

最佳答案

position().right 不存在。只有顶部和左侧。 http://api.jquery.com/position/

将您的条件基于 left 属性,它将起作用

关于javascript - 脚本不进入else语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25482636/

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