移动盒插件回调函数

时间:2012-04-09 17:10:26

标签: javascript jquery

这种紧急情况,所以请有人帮助我......

我正在使用moveboxes插件进行幻灯片放映(这是原始插件:http://css-tricks.com/moving-boxes/) 我需要帮助设置回调函数添加到动画结束。我需要添加淡入淡出效果,当currentSlidecomplete滑动时,它应该开始淡入同一图像的另一个视图,例如,surrentSlide src是images/dr1.jpg,我需要它淡入{ {1}}然后回到images / dr1.jpg。循环浏览每个当前幻灯片

等等 完成:

images/dr1b.jpg

1 个答案:

答案 0 :(得分:0)

您描述的内容已经在文档

请参阅此处的文档[1],更具体地见[2]。

编辑:在这里查看jsfiddle,我使用了jquery插件http://jsfiddle.net/r6yWC/157/ 加载项在这里http://jqueryfordesigners.com/image-cross-fade-transition/ 我还编辑了下面的代码部分。我将类“fade”添加到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/