2012-04-09 54 views
0

这种紧急情况,所以请,有人可以帮我...移动箱插件回调函数

我使用movingboxes插件的幻灯片(这是原来的插件:HTTP:// CSS-技巧。 com/moving-boxes /) 我需要将设置回调函数添加到动画结尾的帮助。我需要添加淡化效果,当currentSlidecomplete滑动时,它应该开始褪色到同一图像的另一个视图,例如,surrentSlide src是images/dr1.jpg,我需要它淡入到images/dr1b.jpg并返回到images/dr1.jpg。通过每个当前幻灯片循环

像 完成:这里

function(e, slider, tar){ 

    //fading for each currentSlide goes here;// 
    } 

回答

0

东西像你描述的是已经在文档

中看到的文档[1],更具体地说这里[2]。

编辑:检查的jsfiddle在这里,我使用一个jquery附加http://jsfiddle.net/r6yWC/157/ 该加载是在这里http://jqueryfordesigners.com/image-cross-fade-transition/ 我还编辑下面的代码段。我说这样的类“变脸”的img标签:

<img class="fade" src="http://chriscoyier.github.com/MovingBoxes/demo/4.jpg" alt="picture" style="background: url(http://chriscoyier.github.com/MovingBoxes/demo/2.jpg);"/> 

在第二连杆你会发现一个完整的回调movingBoxes样品。

(function ($) { 
    $.fn.cross = function (options) { 
     return this.each(function (i) { 
      // cache the copy of jQuery(this) - the start image 
      var $$ = $(this); 

      // get the target from the backgroundImage + regexp 
      var target = $$.css('backgroundImage').replace(/^url|[\(\)'"]/g, ''); 

      // nice long chain: wrap img element in span 
      $$.wrap('<span style="position: relative;"></span>') 
       // change selector to parent - i.e. newly created span 
       .parent() 
       // prepend a new image inside the span 
       .prepend('<img>') 
       // change the selector to the newly created image 
       .find(':first-child') 
       // set the image to the target 
       .attr('src', target); 

      // the CSS styling of the start image needs to be handled 
      // differently for different browsers 
      if ($.browser.msie || $.browser.mozilla) { 
       $$.css({ 
        'position' : 'absolute', 
        'left' : 0, 
        'background' : '', 
        'top' : this.offsetTop 
       }); 
      } else if ($.browser.opera && $.browser.version < 9.5) { 
       // Browser sniffing is bad - however opera < 9.5 has a render bug 
       // so this is required to get around it we can't apply the 'top' : 0 
       // separately because Mozilla strips the style set originally somehow...      
       $$.css({ 
        'position' : 'absolute', 
        'left' : 0, 
        'background' : '', 
        'top' : "0" 
       }); 
      } else { // Safari 
       $$.css({ 
        'position' : 'absolute', 
        'left' : 0, 
        'background' : '' 
       }); 
      } 

      // similar effect as single image technique, except using .animate 
      // which will handle the fading up from the right opacity for us 
      $$.hover(function() { 
       $$.stop().animate({ 
        opacity: 0 
       }, 250); 
      }, function() { 
       $$.stop().animate({ 
        opacity: 1 
       }, 250); 
      }); 
     }); 
    }; 

})(jQuery); 

$('#slider').movingBoxes({ 
// **** Appearance **** 
// start with this panel 
... 
... 

//-----> here is your callback 
// callback after animation completes 
completed: function(e, slider, tar){ 
    var img = slider.$panels.eq(tar).find('img'); 
    img.cross(); 
img.stop().animate({opacity: 0}, 1250).delay(500).animate({opacity: 1}, 2550); 
} 

});​ 

[1] https://github.com/chriscoyier/MovingBoxes/wiki

[2] http://jsfiddle.net/Mottie/r6yWC/2/

+0

谢谢,我看文档已经不workingout对我来说,不得不承认我是新来这个级别的JavaScript和我的努力最难rto学习...你能给我一个例子,说明如何将淡入淡出添加到回调函数中吗?请 ? – marb 2012-04-09 17:32:01

+0

编辑帮助吗? – 2012-04-09 18:57:30

+0

嗨,我在这花了3小时,真的需要让它工作。你可以看看链接,并指导我做错了什么,请:http://jsfiddle.net/marb315/2SfVK/ – marb 2012-04-09 19:52:10