0
您好我已經做了一塊代碼來改變3個div的不透明度。 代碼應每10s顯示#background2,隱藏#background1,然後隱藏background2顯示背景3#...循環與淡入淡出3 divs
<div id="background1" class="backgrounds" style="opacity:1"></div>
<div id="background2" class="backgrounds" style="opacity:0"></div>
<div id="background3" class="backgrounds" style="opacity:0"></div>
<style type="text/css">
#background1{ background-image: url('<?= HTTP_PROJECT_ROOT?>/image/background/1.jpg')}
#background2{ background-image: url('<?= HTTP_PROJECT_ROOT?>/image/background/2.jpg')}
#background3{ background-image: url('<?= HTTP_PROJECT_ROOT?>/image/background/3.jpg')}
.backgrounds{ background-clip: cover;width:100%;height:100%;left: 0px; top: 0px; position: fixed;z-index:-1;}
</style>
<script type="text/javascript">
var nb_background = $('.backgrounds').length;
var id_next_background,id_current_background ='';
function reloadBackground(){
$('.backgrounds').each(function(){
if($(this).css("opacity")=="1"){
id_current_background = $(this).attr("id").replace("background","");
id_next_background = parseInt(id_current_background);
id_next_background ++ ;
if($("#background"+id_next_background).length==0){
id_next_background="1";
}
}
});
$("#background"+id_current_background).animate({opacity:0},2000);
$("#background"+id_next_background).animate({opacity:1},2000);
setTimeout(reloadBackground(),10000);
}
$(function(){
reloadBackground();
});
</script>
它實際上不工作,我得到「最大調用堆棧exceded」 任何想法?
謝謝!