東西像你描述的是已經在文檔
中看到的文檔[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/
謝謝,我看文檔已經不workingout對我來說,不得不承認我是新來這個級別的JavaScript和我的努力最難rto學習...你能給我一個例子,說明如何將淡入淡出添加到回調函數中嗎?請 ? – marb 2012-04-09 17:32:01
編輯幫助嗎? – 2012-04-09 18:57:30
嗨,我在這花了3小時,真的需要讓它工作。你可以看看鏈接,並指導我做錯了什麼,請:http://jsfiddle.net/marb315/2SfVK/ – marb 2012-04-09 19:52:10