问题是,当动画改变div noob背景时,其他div会运行其中的消失,然后重新出现。我想让div noob内的div保持在他们的位置,但只有div noob改变的背景。我怎样才能做到这一点。子divs消失,因为父div的背景使用JQuery更改
我有以下代码:
var currentBackground = 0;
var backgrounds = [];
backgrounds[0] = 'img/m1.jpg';
backgrounds[1] = 'img/m2.jpg';
backgrounds[2] = 'img/m3.jpg';
backgrounds[3] = 'img/m4.jpg';
backgrounds[4] = 'img/m5.jpg';
function changeBackground() {
currentBackground++;
if (currentBackground > 4) currentBackground = 0;
$('#noob').fadeOut(1500, function() {
$('#noob').css({
'background-image': "url('" + backgrounds[currentBackground] + "')"
});
$('#noob').fadeIn(1500);
});
setTimeout(changeBackground, 5000);
}
$(document).ready(function() {
setTimeout(changeBackground, 5000);
});
changeBackground();
.m_i {
float: left;
background-color: cyan;
width: 1366px;
height: 488px;
/*background-image: url(..//img/m1.jpg);*/
}
#hol {
width: 600px;
height: 90px;
margin-left: 383px;
margin-top: 194px;
}
.nam {
width: 600px;
height: 40px;
background-image: url(..//img/new.png);
float: left;
}
.but {
margin-top: 10px;
width: 600px;
height: 40px;
float: left;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="m_i" id="noob">
<div id="hol">
<div class="nam">
</div>
<div class="but">
<button id="bb">W E     A R E     C O R E X</button>
</div>
</div>
<div id="dd" class="local-scroll">
<a href="#yy" class="scroll-down"><i class="fa fa-angle-down scroll-down-icon"></i></a>
</div>
</div>
您能否整理一下您的代码?这是不可读的。如果您不知道如何使用[DirtyMarkup](https://dirtymarkup.com/),请使用[DirtyMarkup]。 – KarthaCoder