star2911 star2911
关注数: 17 粉丝数: 16 发帖数: 408 关注贴吧数: 95
帮忙看看这段代码 (function($) { var aux = { // navigates left / right navigate : function( dir, $el, $wrapper, opts, cache ) { var scroll = opts.scroll, factor = 1, idxClicked = 0; if( cache.expanded ) { scroll = 1; // scroll is always 1 in full mode factor = 3; // the width of the expanded item will be 3 times bigger than 1 collapsed item idxClicked = cache.idxClicked; // the index of the clicked item } // clone the elements on the right / left and append / prepend them according to dir and scroll if( dir === 1 ) { $wrapper.find('div.ca-item:lt(' + scroll + ')').each(function(i) { $(this).clone(true).css( 'left', ( cache.totalItems - idxClicked + i ) * cache.itemW * factor + 'px' ).appendTo( $wrapper ); }); } else { var $first = $wrapper.children().eq(0); $wrapper.find('div.ca-item:gt(' + ( cache.totalItems - 1 - scroll ) + ')').each(function(i) { // insert before $first so they stay in the right order $(this).clone(true).css( 'left', - ( scroll - i + idxClicked ) * cache.itemW * factor + 'px' ).insertBefore( $first ); }); } // animate the left of each item // the calculations are dependent on dir and on the cache.expanded value $wrapper.find('div.ca-item').each(function(i) { var $item = $(this); $item.stop().animate({ left : ( dir === 1 ) ? '-=' + ( cache.itemW * factor * scroll ) + 'px' : '+=' + ( cache.itemW * factor * scroll ) + 'px' }, opts.sliderSpeed, opts.sliderEasing, function() { if( ( dir === 1 && $item.position().left < - idxClicked * cache.itemW * factor ) || ( dir === -1 && $item.position().left > ( ( cache.totalItems - 1 - idxClicked ) * cache.itemW * factor ) ) ) { // remove the item that was cloned $item.remove(); } cache.isAnimating = false; }); }); }, // opens an item (animation) -> opens all the others openItem : function( $wrapper, $item, opts, cache ) { cache.idxClicked = $item.index(); // the item's position (1, 2, or 3) on the viewport (the visible items) cache.winpos = aux.getWinPos( $item.position().left, cache ); $wrapper.find('div.ca-item').not( $item ).hide(); $item.find('div.ca-content-wrapper').css( 'left', cache.itemW + 'px' ).stop().animate({ width : cache.itemW * 2 + 'px', left : cache.itemW + 'px' }, opts.itemSpeed, opts.itemEasing) .end() .stop()
1 下一页