$("#bottomWatch").click(function(){
var doops = $(".videoMove").display;
if (doops == "none") {
$("#video").css("left","15%", "display: block");
} else {
$(".videoMove").css("left","200%", "display: none");
});
我在这里有正确的想法吗?我该怎么做?我想点击按钮,如果id被隐藏,它被显示为块并被拉入,如果不是,它会向后移动200%并隐藏自己。
切换不适用于我正在做的事情。
答案 0 :(得分:6)
您应该使用is
方法:
if ($('.videoMove').is(':hidden')) {
...
} else {
...
}
答案 1 :(得分:1)
试试这个:
$("#bottomWatch").click(function() {
if ($(".videoMove").is(":hidden")) {
console.log("hidden");
$('.videoMove').show().animate({
'left': '200px',
}, "slow", function() {
//callback
});
} else {
$('.videoMove').animate({
'left': '280px'
}, "slow", function() {
//done
$(this).hide();
});
}
});
工作fiddle
答案 2 :(得分:0)
if ($(".videoMove").is(":hidden")) {
///...
}
答案 3 :(得分:0)
.display不是jQuery属性......
替换
var doops = $(".videoMove").display;
与
var doops = $(".videoMove").css('display'); // jQuery Object
OR
var doops = $(".videoMove").get().style.display; // DOM Object