dongxingdu9594 2014-06-07 00:54
浏览 44
已采纳

仅针对背景图像的CSS3过渡

So i have a working JS background changer.

Basically it changes the background every 5 seconds and between the change there is a fadein and fadeout.

However, the div that contains the background has content within in which i dont want to fadein and fadeout everytime the backgrounds are changed. I only want the background image to fadein and fadeout.

Is this possible?

<script type="text/javascript">
  $(window).load(function() {          
  var i =0;
  var images = ['images/mc/bgs/3.jpg','images/mc/bgs/1.png','image1.png'];
  var image = $('#slideit');
                //Initial Background image setup
  image.css('background-image', 'url(images/mc/bgs/3.jpg)');
                //Change image at regular intervals
  setInterval(function(){  
   image.fadeOut(1000, function () {
   image.css('background-image', 'url(' + images [i++] +')');
   image.fadeIn(1000);
   });
   if(i == images.length)
    i = 0;
  }, 5000);           
 });
</script>

Here is the HTML code

<div class="cartregister" id="slideit">
    <div class="container">
         <h1>my content is here, i dont want this fading</h1>
    </div>
</div>

Thanks,

  • 写回答

3条回答 默认 最新

  • duanmie9741 2014-06-07 01:16
    关注

    You just need to place the text and image in different containers, and place text on top of the image with css's position: absolute property:

    html:

    <div class="container">
        <div class="cartregister" id="slideit"></div>
    
    <h1>my content is here, i dont want this fading</h1>
    
    </div>
    

    css:

    .container {
        position:relative;
    }
    .cartregister {
        position:absolute;
        left:0;
        top:0;
        width:800px;
        height:100px;
    }
    h1 {
        z-index:100;
        position:absolute;
        left:0;
        top:0;
    }
    

    demo: http://jsfiddle.net/xq2Q4/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Excel发现不可读取的内容
  • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。