我有两个类,如下:
--- CSS:
.shw-intro {
width: 250px;
height: 150px;
background: rgb(95, 190, 0);
position: absolute;
top: 25px;
left: 50px;
}
.shw-intro-content {
display: none;
}
--- HTML:
<div class="shw-intro">
<div class="shw-intro-content">hello</div>
<div class="shw-intro-content">everyone</div>
<div class="shw-intro-content">have fun</div>
</div>
在javascript中我试图做一些动画,但我两种情况之间惊讶:
var currentShw = 0;
情况1:
function shwAnimation() {
if ($('.shw-intro').attr('class').indexOf('shw-intro-translate') != -1) {
$('.shw-intro').removeClass('shw-intro-translate');
currentShw = currentShw >= $('.shw-intro-content').length ? 0 : currentShw + 1;
}
else {
$('.shw-intro').children().eq(currentShw).show(); // It works fine
$('.shw-intro').addClass('shw-intro-translate');
}
}
情况2:
function shwAnimation() {
if ($('.shw-intro').attr('class').indexOf('shw-intro-translate') != -1) {
$('.shw-intro').removeClass('shw-intro-translate');
currentShw = currentShw >= $('.shw-intro-content').length ? 0 : currentShw + 1;
}
else {
$('.shw-intro').children('shw-intro-content').eq(currentShw).show(); // It doesn't work
$('.shw-intro').addClass('shw-intro-translate');
}
}
有什么惊喜? – Mikhail
情况2不起作用 – HICURIN
'shw-intro-content'查找标记名称为'的元素。你忘了在它前面添加'.',使它成为一个类选择器。 –
Blender