我有两个班如下:
- 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');
}
}发布于 2013-12-09 04:44:33
您应该使用CSS选择器作为.children()的参数。
像这样:$('.shw-intro').children('.shw-intro-content')
发布于 2013-12-09 04:46:02
这应该能行
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();
$('.shw-intro').addClass('shw-intro-translate');
}
}必须通过使用“”来使用类选择器。
https://stackoverflow.com/questions/20463235
复制相似问题