-2

我的代码在这里不起作用......关于将什么作为 if 语句的条件放入的任何其他想法?非常感谢任何帮助。谢谢!

HTML:

<img class="image image1" src="images/spongebob1.jpg" />

CSS:

.image {
height: 94%;
margin: 0 auto;
position: absolute;
animation: moveSlider 5s 1;
-webkit-animation: moveSlider 5s 1;
}
@keyframes moveSlider {
from {left:0px;}
to {left:200px;}
}
@-webkit-keyframes moveSlider {
from {opacity:0;}
to {opacity:1;}
}

JS:

$(document).ready(function() {
    $(".image2, .image3, .image4, .image5").hide();
    if ($(".image1").css('opacity') === '1') {
        $(".image1").hide();
    } 
});
4

3 回答 3

1

问题似乎是您使用 1 作为字符串。=== 不会将字符串转换为整数

if ($(".image1").css('opacity') === '1') {
    $(".image1").hide();
} 

尝试 === 1 而不是 '1'

于 2012-10-22T19:00:59.910 回答
1

Try changing line 3 of your JS to this:

if ($('.image1').is(':visible')) {

Also, try to be consistent with how you use your " vs ' --you're mixing them in the original line. This is mostly just to make your life easier.

于 2012-10-22T19:01:44.643 回答
0
$(document).ready(function() {
    $(".image2, .image3, .image4, .image5").hide();
    if ($(".image1").css({'opacity':'1'}) === true) {
        $(".image1").hide();
    } 
});
于 2012-10-22T19:29:17.003 回答