简体   繁体   English

尝试在背景图像之间添加平滑的图像过渡

[英]Trying to add smooth Image transition between background images

This is the code I currently have: 这是我目前拥有的代码:

  $('ul.whats_new_ul li').click(function(){
      var tab_id = $(this).attr('data-tab');
      $('ul.whats_new_ul li').removeClass('current');
      $('.tab-content').removeClass('current');
      $(this).addClass('current');
      $("#"+tab_id).addClass('current');


      if(tab_id == 'Messages'){
          $('#what_new_back').css('background-image', 'url(img/mobile-app/global/whts_new.jpg)' );
      }else if(tab_id == 'gift'){
          $('#what_new_back').css('background-image', 'url(img/mobile-app/global/gift_back.jpg)' );
      }else if(tab_id == 'locators'){
          $('#what_new_back').css('background-image', 'url(img/mobile-app/global/locater.jpg)' );
      }else if(tab_id == 'menu'){
          $('#what_new_back').css('background-image', 'url(img/mobile-app/global/menu_back.jpg)' );
      }
  });   

to see it clearer in action - this link here - under section What's New 看到它在行动更加清晰-此链接在这里 -第新增

I wondering how do I add a smooth transition between clicks and make sure the background image has the slideUp animation when each tab is clicked? 我想知道如何在单击之间添加平滑过渡,并确保单击每个选项卡时背景图像具有slideUp动画吗?

See this please: 请看这个:

Animate background image change with jQuery 使用jQuery动画背景图像更改

It is not possible to animate the background itself, but it is possible to animate the element containing the background. 不能对背景本身进行动画处理,但是可以对包含背景的元素进行动画处理。

Without your HTML and CSS I can't give you a correct response but I think that this demo can help you 没有您的HTML和CSS,我无法给您正确的答案,但我认为此演示可以帮助您

http://css3.bradshawenterprises.com/cfimg/ http://css3.bradshawenterprises.com/cfimg/

Basically you can't animate backgrounds, you need to use divs or imgs and animate them. 基本上,您不能为背景设置动画,需要使用div或img对其进行动画处理。

"Demo 6 -Fading between multiple images on click" “演示6-单击时在多个图像之间淡入”

<div id="cf7" class="shadow">
  <img class='opaque' src="/images/Windows%20Logo.jpg" />
  <img src="/images/Turtle.jpg;" />
  <img src="/images/Rainbow%20Worm.jpg;" />
  <img src="/images/Birdman.jpg;" />
</div>

You can use a wrapper (#backgrounds, #content), use position:absolute and z-index. 您可以使用包装器(#backgrounds,#content),使用position:absolute和z-index。 Something like 就像是

<div style="position:relative">
  <div id="content" style="position:absolute;top:0;left:0;width:100%;height:100%;z-index:20">
  ...
  </div>

  <div id="backgrounds" style="position:absolute;top:0;left:0;width:100%;height:100%;z-index:10">
    <img .../>
    <img .../>
    ...
  </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM