2013-04-09 47 views
0

我有点新的jQuery和需要一些帮助,我搜索了解决方案的网络,并试图编辑它,以满足我的要求。我想要的是更改背景事件,并且内容中还有一个滑块,当更改控件时,背景也会改变。我已经做到了,但我有2个问题:动画和重置间隔

  1. 我需要重新设置间隔时,其点击(现在它 混合起来)
  2. 我需要动画背景的变化insted的 变化的直接(或易于褪色)

这里是代码: -

$(window).load(function(){ 
    var images = ['images/background/body-bg.jpg','images/background/body-bg2.jpg']; 
    var i = 0; 

    function changeBackground() { 
     $('html').css({ 
      'background': function(){ 
          if (i >= images.length) { 
           i=0; 
          } 
          return 'url(' + images[i++] + ')'; 

         }, 
      'background-position':'center', 
      'background-attachment':'fixed', 
      'background-size':'cover' 
     }) 
    } 

    // Call it on the first time 
    changeBackground(); 

    (function(){ 
     $('.sliderControl > li').children().on('click', function(){ 
      changeBackground(); 
      window.clearInterval() 
     }) 
    })(); 

    // Set an interval to continue 
    setInterval(changeBackground, 5000); 

}); 

回答

0

使用JS吐温库您达致这很容易

http://www.jstween.org/

      { 
      id: "JSframe1", 
      //audio: "<filename and path, without extension>", 
      play: function(JQtarget, FNcallback) { 
       JQtarget.find(".JSimage1").tween({ 



         transform:{ 
          start: 'rotate(0deg) scale(1)', 
          stop: 'rotate(360deg) scale(1)', 
          time: 0, 
          duration: 1, 
          effect:'linear' 
          }, 
          width: { 
          start: 1, 
          stop: 100, 
          time: 0, 
          duration: 1, 
          units: '%' 

          }, 
          height: { 
          start: 1, 
          stop: 100, 
          time: 0, 
          duration: 1, 
          units: '%' 
          }, 


       }); 
       setTimeout(FNcallback, 7000); 
       $.play(); 
      } 
     },