jQuery图像淡出不起作用

时间:2015-03-05 12:35:39

标签: javascript jquery

您好我写了一些jQuery但由于某种原因褪色不起作用

$(document).ready(function () {

    var img_array = [1, 2, 3, 4],
        newIndex = 0,
        index = 0,
        interval = 7500;

    (function changeBg() {


        //  newIndex = Math.floor(Math.random() * 10) % img_array.length;
        //  index = (newIndex === index) ? newIndex -1 : newIndex;

        index = (index + 1) % img_array.length;

        $('.main-wrapper').css('backgroundImage', function () {
            $('#cycler').fadeIn({
                backgroundColor: 'transparent'
            }, 0, function () {
                setTimeout(function () {
                    $('#cycler').fadeToggle({
                        backgroundImage: 'url(http://dev.test.co.uk/Content/H/images/bg1.png)'
                    }, 2500);
                }, 4000);
            });
            return 'url(http://dev.test.co.uk/Content/H/images/bg' + img_array[index] + '.png)';
        });
        setTimeout(changeBg, interval);
    })();
});

请有人对此有所了解

HTML实际上只是中间的一些内容,而只是一些文本

<section id="cycler" class="main-wrapper"></section>

和css是:

#cycler{
    position:relative;
}

#cycler img{
    z-index:1
}

#cycler img.active{
    z-index:3
}

.main-wrapper 
{    
    overflow-x: auto;
    margin-left: auto;
    margin-right: auto;
    height: 1822px;    
    background-image: url(../H/images/bgone.png);
    background-size: cover;
    background-repeat: no-repeat;
}

任何帮助都很好

谢谢

1 个答案:

答案 0 :(得分:1)

Tim现在最好使用带引导程序的css3和html吗?

<div class="carousel-wrapper">
    <!-- Header Carousel -->
   <div id="carousel" class="carousel slide carousel-fade" data-ride="carousel">  
    <div class="carousel-inner">
      <div class="active item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
    </div>
  </div>
</div>

CSS

.carousel-fade .carousel-inner .item 
{
  opacity: 0;
  transition-property: opacity; 
}
.carousel-fade .carousel-inner .active 
{
  opacity: 1; 
}
.carousel-fade .carousel-inner .active.left,
.carousel-fade .carousel-inner .active.right 
{
  left: 0;
  opacity: 0;
  z-index: 1; 
}
.carousel-fade .carousel-inner .next.left,
.carousel-fade .carousel-inner .prev.right 
{
  opacity: 1; 
}
.carousel-fade .carousel-control 
{
  z-index: 2; 
}

.carousel-wrapper 
{
 width: 100%;
 background-color: #000000;
}
/* html,
body, */
.carousel,
.carousel-inner,
.carousel-inner .item 
{
  min-width: 1200px;
  max-width: 1200px;
  min-height: 512px;   
  max-height: 512px;  
  margin-right: auto;
  margin-left: auto;
}


.item:nth-child(1) 
{
  background-image: url('image0.png'); 
}

.item:nth-child(2)
{
  background-image: url('image1.png'); 
}

.item:nth-child(3) 
{
  background-image: url('image2.png'); 
}

.item:nth-child(4) 
{
  background-image: url('image3.png'); 
}

jQuery

$('.carousel').carousel({
    interval: 5000 //changes the speed
})

希望这有帮助