【问题标题】:jQuery prev/next button in polaroid gallery plugin宝丽来画廊插件中的jQuery上一个/下一个按钮
【发布时间】:2019-02-10 17:06:18
【问题描述】:

我正在使用宝丽来图片库插件。它的工作方式是,宝丽来图像分散在一个 div 中,底部有一些圆形导航按钮,可以单击以激活所选图像并将其移动到中间。

我不想使用圆形导航按钮来选择每张图片,而是使用上一个/下一个按钮(这样当画廊有超过 20 张照片时,它就不会显示 20 多个圆形导航图标)。

我能够添加一些上一个/下一个按钮并让它们工作,但有一个小问题我无法弄清楚。当画廊加载时,如果您选择上一个/下一个按钮,画廊将按预期工作,单击按钮时它将根据需要切换照片。但是,如果用户单击图库中的任何位置(而不是按钮),它将随机播放所有照片(不应随机播放),然后一旦用户这样做,上一个/下一个按钮将不再起作用,直到页面被刷新.

我仍在学习 jQuery/js,但我无法弄清楚是什么原因造成的。只有在选择了上一个/下一个按钮时,我才需要限制照片的随机播放和选择,因为如果用户不小心点击了图库中的任何位置,按钮就会中断。

我创建了一个 jsfiddle here

html 非常简单,这是我添加的上一个/下一个按钮的示例:

<section id="photostack-1" class="photostack photostack-start">
  <div>
        <figure>
            <a href="" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/5.jpg" alt="img05"/></a>
            <figcaption>
               <h2 class="photostack-title">Speed Racer</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/2.jpg" alt="img02"/></a>
            <figcaption>
                <h2 class="photostack-title">Happy Days</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/3.jpg" alt="img03"/></a>
            <figcaption>
                <h2 class="photostack-title">Beautywood</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/1.jpg" alt="img01"/></a>
            <figcaption>
                <h2 class="photostack-title">Serenity Beach</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/4.jpg" alt="img04"/></a>
            <figcaption>
                <h2 class="photostack-title">Heaven of time</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/6.jpg" alt="img06"/></a>
            <figcaption>
                <h2 class="photostack-title">Forever this</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/7.jpg" alt="img07"/></a>
            <figcaption>
                <h2 class="photostack-title">Lovely Green</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/8.jpg" alt="img08"/></a>
            <figcaption>
                <h2 class="photostack-title">Wonderful</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/9.jpg" alt="img09"/></a>
            <figcaption>
                <h2 class="photostack-title">Love Addict</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/10.jpg" alt="img10"/></a>
            <figcaption>
                <h2 class="photostack-title">Friendship</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/11.jpg" alt="img11"/></a>
            <figcaption>
                <h2 class="photostack-title">White Nights</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/12.jpg" alt="img12"/></a>
            <figcaption>
                <h2 class="photostack-title">Serendipity</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/13.jpg" alt="img13"/></a>
            <figcaption>
                <h2 class="photostack-title">Pure Soul</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/14.jpg" alt="img14"/></a>
            <figcaption>
                <h2 class="photostack-title">Winds of Peace</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/15.jpg" alt="img15"/></a>
            <figcaption>
                <h2 class="photostack-title">Shades of blue</h2>
            </figcaption>
        </figure>
        <figure>
            <a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/16.jpg" alt="img16"/></a>
            <figcaption>
                <h2 class="photostack-title">Lightness</h2>
            </figcaption>
        </figure>
    </div>
    <!-- Next and Previous controls -->
    <div id="imageControls">
        <button id="leftArrowGallery" class="btnGallery"><i class="fa fa-chevron-left"></i></button>
        <button id="rightArrowGallery" class="btnGallery"><i class="fa fa-chevron-right"></i></button>
    </div>
</section>

用于添加上一个/下一个按钮和删除圆形导航图标的自定义jQuery是:

var ps = new Photostack( document.getElementById( 'photostack-1' ), {});
        $("#leftArrowGallery").prependTo($(".photostack > nav"));
        $("#rightArrowGallery").appendTo($(".photostack > nav"));

        $("#leftArrowGallery").on("click", function () {
            ps.navigate('prev');
        });

        $("#rightArrowGallery").on("click", function () {
            ps.navigate('next');
        });

        $(".photostack > nav > span").each(function(){ $(this).remove(); });

可以在jsfiddle中查看该插件的所有js。

带有圆形导航图标的原始画廊的屏幕截图示例:

添加了自定义上一个/下一个按钮的图库的屏幕截图示例:

同样,按钮工作正常,我只需要防止当有人点击图库中的任何位置时,它会随机播放图像,然后上一个/下一个按钮会中断并且在页面刷新之前不再工作。

感谢您的帮助!

【问题讨论】:

    标签: javascript jquery html css


    【解决方案1】:

    我读了你的代码,我发现当你放photostack-start 类时最大的问题是每次你点击 photostack 阶段时,你都会随机播放你的照片两次:一次在_photoShow 函数中,一次在open 函数中(每次都会触发open函数)。要解决您的问题,解决方案可能是停止一个混杂的行动。为此,我创建了一个变量并将其放入 open 函数中:

    if( this.open ) {
        return false;
    }
    this.open = true;
    

    现在,_open 函数仅触发一次(当您单击“查看图库”按钮时),之后只有 _photoShow 起作用,因此您的代码最终可以按您的意愿运行。

    小心:在这个例子中,我删除了一些图片,因为我在这里有字符限制(30000),但代码仍然可以处理更多图片。

    更多图片:https://jsfiddle.net/m46cxkhg/217/(已使用 Chrome 和 Firefox 测试)

    ;( function( window ) {
    
    	'use strict';
    
    	Modernizr.addTest('csstransformspreserve3d', function () {
    		var prop = Modernizr.prefixed('transformStyle');
    		var val = 'preserve-3d';
    		var computedStyle;
    		if(!prop) return false;
    
    		prop = prop.replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');
    
    		Modernizr.testStyles('#modernizr{' + prop + ':' + val + ';}', function (el, rule) {
    			computedStyle = window.getComputedStyle ? getComputedStyle(el, null).getPropertyValue(prop) : '';
    		});
    
    		return (computedStyle === val);
    	});
    
    	var support = { 
    			transitions : Modernizr.csstransitions,
    			preserve3d : Modernizr.csstransformspreserve3d
    		},
    		transEndEventNames = {
    			'WebkitTransition': 'webkitTransitionEnd',
    			'MozTransition': 'transitionend',
    			'OTransition': 'oTransitionEnd',
    			'msTransition': 'MSTransitionEnd',
    			'transition': 'transitionend'
    		},
    		transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ];
    
    	function extend( a, b ) {
    		for( var key in b ) { 
    			if( b.hasOwnProperty( key ) ) {
    				a[key] = b[key];
    			}
    		}
    		return a;
    	}
    
    	function shuffleMArray( marray ) {
    		var arr = [], marrlen = marray.length, inArrLen = marray[0].length;
    		for(var i = 0; i < marrlen; i++) {
    			arr = arr.concat( marray[i] );
    		}
    		
    		arr = shuffleArr( arr );
    	
    		var newmarr = [], pos = 0;
    		for( var j = 0; j < marrlen; j++ ) {
    			var tmparr = [];
    			for( var k = 0; k < inArrLen; k++ ) {
    				tmparr.push( arr[ pos ] );
    				pos++;
    			}
    			newmarr.push( tmparr );
    		}
    		return newmarr;
    	}
    
    	function shuffleArr( array ) {
    		var m = array.length, t, i;
    		
    		while (m) {
    			
    			i = Math.floor(Math.random() * m--);
    			
    			t = array[m];
    			array[m] = array[i];
    			array[i] = t;
    		}
    		return array;
    	}
    
    	function Photostack( el, options ) {
    		this.el = el;
    		this.inner = this.el.querySelector( 'div' );
    		this.allItems = [].slice.call( this.inner.children );
    		this.allItemsCount = this.allItems.length;
    		if( !this.allItemsCount ) return;
    		this.items = [].slice.call( this.inner.querySelectorAll( 'figure:not([data-dummy])' ) );
    		this.itemsCount = this.items.length;
    		this.options = extend( {}, this.options );
      	extend( this.options, options );
     		
    		this.current = this.options.start;
      	this._init();
    		var ps = this;
    
      	
      	return {
      		showPhoto: function(idx) {
      			ps._showPhoto.call(ps, idx);
      		},
      		open: function() {
      			ps._open.call(ps, true);
      		},
      		navigate: function(dir) {
      			ps._navigate.call(ps, dir);
            
      		},
      	}
    	}
    
    	Photostack.prototype.options = {
    		start: 0,
    		showNavigation: true,
    		afterInit: null,
    		afterShowPhoto: null,
    		afterNavigate: null
    	};
    
    	Photostack.prototype._init = function() {
    		this.currentItem = this.items[ this.current ];
    		if(this.options.showNavigation) {
    			this._addNavigation();
    		}
    		this._getSizes();
    		this._initEvents();
    		if(this.options.afterInit) {
    			this.options.afterInit(this);
    		}
    	}
    
    	Photostack.prototype._addNavigation = function() {
    		// add nav dots
    		this.nav = document.createElement( 'nav' )
    		var inner = '';
    		for( var i = 0; i < this.itemsCount; ++i ) {
    			inner += '<span></span>';
    		}
    		this.nav.innerHTML = inner;
    		this.el.appendChild( this.nav );
    		this.navDots = [].slice.call( this.nav.children );
    	}
    
    	Photostack.prototype._open = function( beforeStep ) {
        /* I added this */
      	if( this.open ) {
    			return false;
    		}
    		this.open = true;
        /* End of change */
    
    		var self = this,
    		el = this.el;
    		var setTransition = function() { 
    			if( support.transitions ) {
    				classie.addClass( el, 'photostack-transition' ); 
    			}
    		}
    		if( beforeStep ) {
    			el.removeEventListener( 'click', open ); 
    			classie.removeClass( el, 'photostack-start' );
    			setTransition();
    		}
    		else {
    			self.openDefault = true;
    			setTimeout( setTransition, 25 );
    		}
    		self.started = true; 
    		self._showPhoto( self.current );
    	};
    
    	Photostack.prototype._initEvents = function() {
    		if(this.options.clickToFlip == 'true')
    		{
    			this.items.forEach(function(img, idx){
    				img.addEventListener('click', function(event){
    					event.preventDefault();
    					if( idx === self.current ) {
    						self._rotateItem();
    					}
    				})
    			});
    		}
    		
    		var self = this,
    			beforeStep = classie.hasClass( this.el, 'photostack-start' );
    
    		if( beforeStep ) {
    			this._shuffle();
    			this.el.addEventListener( 'click', function() {
    				self._open(beforeStep);
    			});
    		}
    		else {
    			this._open(beforeStep);
    		}
    
    		if(this.options.showNavigation) {
    			this.navDots.forEach( function( dot, idx ) {
    				dot.addEventListener( 'click', function() {
    					
    					if( idx === self.current ) {
    						self._rotateItem();
    					}
    					else {
    						// if the photo is flipped then rotate it back before shuffling again
    						var callback = function() { self._showPhoto( idx ); }
    						if( self.flipped ) {
    							self._rotateItem( callback );
    						}
    						else {
    							callback();
    						}
    					}
    				} );
    			} );
    		}
    
    		window.addEventListener( 'resize', function() { self._resizeHandler(); } );
    	}
    
    	Photostack.prototype._resizeHandler = function() {
    		var self = this;
    		function delayed() {
    			self._resize();
    			self._resizeTimeout = null;
    		}
    		if ( this._resizeTimeout ) {
    			clearTimeout( this._resizeTimeout );
    		}
    		this._resizeTimeout = setTimeout( delayed, 100 );
    	}
    
    	Photostack.prototype._resize = function() {
    		var self = this, callback = function() { self._shuffle( true ); }
    		this._getSizes();
    		if( this.started && this.flipped ) {
    			this._rotateItem( callback );
    		}
    		else {
    			callback();
    		}
    	}
    
    	Photostack.prototype._showPhoto = function( pos ) {
    		if( this.isShuffling ) {
    			return false;
    		}
    		this.isShuffling = true;
    
    		// if there is something behind..
    		if( classie.hasClass( this.currentItem, 'photostack-flip' ) ) {
    			this._removeItemPerspective();
    			if(this.options.showNavigation) {
    				classie.removeClass( this.navDots[ this.current ], 'flippable' );
    			}
    		}
    
    		if(this.options.showNavigation) {
    			classie.removeClass( this.navDots[ this.current ], 'current' );
    		}
    		classie.removeClass( this.currentItem, 'photostack-current' );
    		
    		// change current
    		this.current = pos;
    		this.currentItem = this.items[ this.current ];
    		
    		if(this.options.showNavigation) {
    			classie.addClass( this.navDots[ this.current ], 'current' );
    		}
    		// if there is something behind..
    		if( this.options.showNavigation && this.currentItem.querySelector( '.photostack-back' ) ) {
    			// nav dot gets class flippable
    			classie.addClass( this.navDots[ pos ], 'flippable' );
    		}
    
    		// shuffle a bit
    		this._shuffle();
    
    		if(this.options.afterShowPhoto) {
    			this.options.afterShowPhoto(this);
    		}
    	}
    
    	// display items (randomly)
    	Photostack.prototype._shuffle = function( resize ) {
    		var iter = resize ? 1 : this.currentItem.getAttribute( 'data-shuffle-iteration' ) || 1;
    		if( iter <= 0 || !this.started || this.openDefault ) { iter = 1; }
    		// first item is open by default
    		if( this.openDefault ) {
    			// change transform-origin
    			classie.addClass( this.currentItem, 'photostack-flip' );
    			this.openDefault = false;
    			this.isShuffling = false;
    		}
    		
    		var overlapFactor = .5,
    			// lines & columns
    			lines = Math.ceil(this.sizes.inner.width / (this.sizes.item.width * overlapFactor) ),
    			columns = Math.ceil(this.sizes.inner.height / (this.sizes.item.height * overlapFactor) ),
    			// since we are rounding up the previous calcs we need to know how much more we are adding to the calcs for both x and y axis
    			addX = lines * this.sizes.item.width * overlapFactor + this.sizes.item.width/2 - this.sizes.inner.width,
    			addY = columns * this.sizes.item.height * overlapFactor + this.sizes.item.height/2 - this.sizes.inner.height,
    			// we will want to center the grid
    			extraX = addX / 2,
    			extraY = addY / 2,
    			// max and min rotation angles
    			maxrot = 35, minrot = -35,
    			self = this,
    			// translate/rotate items
    			moveItems = function() {
    				--iter;
    				// create a "grid" of possible positions
    				var grid = [];
    				// populate the positions grid
    				for( var i = 0; i < columns; ++i ) {
    					var col = grid[ i ] = [];
    					for( var j = 0; j < lines; ++j ) {
    						var xVal = j * (self.sizes.item.width * overlapFactor) - extraX,
    							yVal = i * (self.sizes.item.height * overlapFactor) - extraY,
    							olx = 0, oly = 0;
    
    						if( self.started && iter === 0 ) {
    							var ol = self._isOverlapping( { x : xVal, y : yVal } );
    							if( ol.overlapping ) {
    								olx = ol.noOverlap.x;
    								oly = ol.noOverlap.y;
    								var r = Math.floor( Math.random() * 3 );
    								switch(r) {
    									case 0 : olx = 0; break;
    									case 1 : oly = 0; break;
    								}
    							}
    						}
    
    						col[ j ] = { x : xVal + olx, y : yVal + oly };
    					}
    				}
    				// shuffle
    				grid = shuffleMArray(grid);
    
    				var l = 0, c = 0, cntItemsAnim = 0;
    				self.allItems.forEach( function( item, i ) {
    					// pick a random item from the grid
    					if( l === lines - 1 ) {
    						c = c === columns - 1 ? 0 : c + 1;
    						l = 1;
    					}
    					else {
    						++l
    					}
    
    					var randXPos = Math.floor( Math.random() * lines ),
    						randYPos = Math.floor( Math.random() * columns ),
    						gridVal = grid[c][l-1],
    						translation = { x : gridVal.x, y : gridVal.y },
    						onEndTransitionFn = function() {
    							++cntItemsAnim;
    							if( support.transitions ) {
    								this.removeEventListener( transEndEventName, onEndTransitionFn );
    							}
    							if( cntItemsAnim === self.allItemsCount ) {
    								if( iter > 0 ) {
    									moveItems.call();
    								}
    								else {
    									// change transform-origin
    									classie.addClass( self.currentItem, 'photostack-flip' );
    									// all done..
    									self.isShuffling = false;
    									if( typeof self.options.callback === 'function' ) {
    										self.options.callback( self.currentItem );
    									}
    								}
    							}
    						};
    
    					if(self.items.indexOf(item) === self.current && self.started && iter === 0) {
    						self.currentItem.style.WebkitTransform = 'translate(' + self.centerItem.x + 'px,' + self.centerItem.y + 'px) rotate(0deg)';
    						self.currentItem.style.msTransform = 'translate(' + self.centerItem.x + 'px,' + self.centerItem.y + 'px) rotate(0deg)';
    						self.currentItem.style.transform = 'translate(' + self.centerItem.x + 'px,' + self.centerItem.y + 'px) rotate(0deg)';
    						// if there is something behind..
    						if( self.currentItem.querySelector( '.photostack-back' ) ) {
    							self._addItemPerspective();
    						}
    						classie.addClass( self.currentItem, 'photostack-current' );
    					}
    					else {
    						item.style.WebkitTransform = 'translate(' + translation.x + 'px,' + translation.y + 'px) rotate(' + Math.floor( Math.random() * (maxrot - minrot + 1) + minrot ) + 'deg)';
    						item.style.msTransform = 'translate(' + translation.x + 'px,' + translation.y + 'px) rotate(' + Math.floor( Math.random() * (maxrot - minrot + 1) + minrot ) + 'deg)';
    						item.style.transform = 'translate(' + translation.x + 'px,' + translation.y + 'px) rotate(' + Math.floor( Math.random() * (maxrot - minrot + 1) + minrot ) + 'deg)';
    					}
    
    					if( self.started ) {
    						if( support.transitions ) {
    							item.addEventListener( transEndEventName, onEndTransitionFn );
    						}
    						else {
    							onEndTransitionFn();
    						}
    					}
    				} );
    			};
    
    		moveItems.call();
    	}
    
    	Photostack.prototype._navigate = function(dir) {
    		var current = this.current,
    		itemsCount = this.itemsCount,
    		lastItem = itemsCount - 1,
    		idx = 0;
    		if(dir == 'next') {
    			idx = current < lastItem ? current + 1 : 0
    		} else if(dir == 'prev') {
    			idx = current > 0 ? current - 1 : lastItem;
    		}
    
    		this._showPhoto(idx);
        
    		if(this.options.afterNavigate) {
    			this.options.afterNavigate(this);
    		}
    	}
    
    	Photostack.prototype._getSizes = function() {
    		this.sizes = {
    			inner : { width : this.inner.offsetWidth, height : this.inner.offsetHeight },
    			item : { width : this.currentItem.offsetWidth, height : this.currentItem.offsetHeight }
    		};
    		
    		// translation values to center an item
    		this.centerItem = { x : this.sizes.inner.width / 2 - this.sizes.item.width / 2, y : this.sizes.inner.height / 2 - this.sizes.item.height / 2 };
    	}
    
    	Photostack.prototype._isOverlapping = function( itemVal ) {
    		var dxArea = this.sizes.item.width + this.sizes.item.width / 3, // adding some extra avoids any rotated item to touch the central area
    			dyArea = this.sizes.item.height + this.sizes.item.height / 3,
    			areaVal = { x : this.sizes.inner.width / 2 - dxArea / 2, y : this.sizes.inner.height / 2 - dyArea / 2 },
    			dxItem = this.sizes.item.width,
    			dyItem = this.sizes.item.height;
    
    		if( !(( itemVal.x + dxItem ) < areaVal.x ||
    			itemVal.x > ( areaVal.x + dxArea ) ||
    			( itemVal.y + dyItem ) < areaVal.y ||
    			itemVal.y > ( areaVal.y + dyArea )) ) {
    				// how much to move so it does not overlap?
    				// move left / or move right
    				var left = Math.random() < 0.5,
    					randExtraX = Math.floor( Math.random() * (dxItem/4 + 1) ),
    					randExtraY = Math.floor( Math.random() * (dyItem/4 + 1) ),
    					noOverlapX = left ? (itemVal.x - areaVal.x + dxItem) * -1 - randExtraX : (areaVal.x + dxArea) - (itemVal.x + dxItem) + dxItem + randExtraX,
    					noOverlapY = left ? (itemVal.y - areaVal.y + dyItem) * -1 - randExtraY : (areaVal.y + dyArea) - (itemVal.y + dyItem) + dyItem + randExtraY;
    
    				return {
    					overlapping : true,
    					noOverlap : { x : noOverlapX, y : noOverlapY }
    				}
    		}
    		return {
    			overlapping : false
    		}
    	}
    
    	Photostack.prototype._addItemPerspective = function() {
    		classie.addClass( this.el, 'photostack-perspective' );
    	}
    
    	Photostack.prototype._removeItemPerspective = function() {
    		classie.removeClass( this.el, 'photostack-perspective' );
    		classie.removeClass( this.currentItem, 'photostack-flip' );
    	}
    
    	Photostack.prototype._rotateItem = function( callback ) {
    		if( classie.hasClass( this.el, 'photostack-perspective' ) && !this.isRotating && !this.isShuffling ) {
    			this.isRotating = true;
    
    			var self = this, onEndTransitionFn = function() {
    					if( support.transitions && support.preserve3d ) {
    						this.removeEventListener( transEndEventName, onEndTransitionFn );
    					}
    					self.isRotating = false;
    					if( typeof callback === 'function' ) {
    						callback();
    					}
    				};
    
    			if( this.flipped ) {
    				if(this.options.showNavigation) {
    					classie.removeClass( this.navDots[ this.current ], 'flip' );
    				}
    				if( support.preserve3d ) {
    					this.currentItem.style.WebkitTransform = 'translate(' + this.centerItem.x + 'px,' + this.centerItem.y + 'px) rotateY(0deg)';
    					this.currentItem.style.transform = 'translate(' + this.centerItem.x + 'px,' + this.centerItem.y + 'px) rotateY(0deg)';
    				}
    				else {
    					classie.removeClass( this.currentItem, 'photostack-showback' );
    				}
    			}
    			else {
    				if(this.options.showNavigation) {
    					classie.addClass( this.navDots[ this.current ], 'flip' );
    				}
    				if( support.preserve3d ) {
    					this.currentItem.style.WebkitTransform = 'translate(' + this.centerItem.x + 'px,' + this.centerItem.y + 'px) translate(' + this.sizes.item.width + 'px) rotateY(-179.9deg)';
    					this.currentItem.style.transform = 'translate(' + this.centerItem.x + 'px,' + this.centerItem.y + 'px) translate(' + this.sizes.item.width + 'px) rotateY(-179.9deg)';
    				}
    				else {
    					classie.addClass( this.currentItem, 'photostack-showback' );
    				}
    			}
    
    			this.flipped = !this.flipped;
    			if( support.transitions && support.preserve3d ) {
    				this.currentItem.addEventListener( transEndEventName, onEndTransitionFn );
    			}
    			else {
    				onEndTransitionFn();
    			}
    		}
    	}
    
    	// add to global namespace
    	window.Photostack = Photostack;
    
    })( window );
        
        
    var ps = new Photostack( document.getElementById( 'photostack-1' ), {});
    		$("#leftArrowGallery").prependTo($(".photostack > nav"));
    		$("#rightArrowGallery").appendTo($(".photostack > nav"));
    		
    		$("#leftArrowGallery").on("click", function () {
    			ps.navigate('prev');
    		});
    
    		$("#rightArrowGallery").on("click", function () {
    			ps.navigate('next');
    		});
    
    		$(".photostack > nav > span").each(function(){ $(this).remove(); });
    .photostack {
    	background: #ddd;
    	position: relative;
    	text-align: center;
    	overflow: hidden;
    }
    
    .js .photostack {
    	height: 580px;
    }
    .photostack-start {
    	cursor: pointer;
    }
    
    .photostack > div {
    	width: 100%;
    	height: 100%;
    	margin: 0 auto;
    }
    
    .photostack figure {
    	width: 320px;
    	height: 360px;
    	position: relative;
    	display: inline-block;
    	background: #fff;
    	padding: 40px;
    	text-align: center;
    	margin: 5px;
    }
    
    .js .photostack figure {
    	position: absolute;
    	display: block;
    	margin: 0;
    }
    
    .photostack figcaption h2 {
    	margin: 20px 0 0 0;
    	color: #a7a0a2;
    	font-size: 16px;
    }
    
    .photostack-img {
    	outline: none;
    	width: 240px;
    	height: 240px;
    	background: #f9f9f9;
    }
    
    .photostack-back {
    	display: none;
    	position: absolute;
    	width: 100%;
    	height: 100%;
    	top: 0;
    	left: 0;
    	background: #fff;
    	font-family: "Give You Glory", cursive;
    	color: #a7a0a2;
    	padding: 50px 40px;
    	text-align: left;
    	font-size: 22px;
    	line-height: 1.25;
    	z-index: 1;
    }
    
    .photostack-back p {
    	margin: 0;
    }
    
    .photostack-back p span {
    	text-decoration: line-through;
    }
    
    .photostack nav {
    	position: absolute;
    	width: 100%;
    	bottom: 30px;
    	z-index: 90;
    	text-align: center;
    	left: 0;
    	-webkit-transition: opacity 0.3s;
    	transition: opacity 0.3s;
    }
    
    .photostack-start nav {
    	opacity: 0;
    }
     
    .photostack nav span {
    	position: relative;
    	display: inline-block;
    	margin: 0 5px;
    	width: 30px;
    	height: 30px;
    	cursor: pointer;
    	background: #aaa;
    	border-radius: 50%;
    	text-align: center;
    	-webkit-transition: -webkit-transform 0.6s ease-in-out, background 0.3s;
    	transition: transform 0.6s ease-in-out, background 0.3s;
    	-webkit-transform: scale(0.48);
    	transform: scale(0.48);
    }
    
    .photostack nav span:last-child {
    	margin-right: 0;
    }
    
    .photostack nav span::after {
    	content: "\e600";
    	font-family: 'icons';
    	font-size: 80%;
    	speak: none;
    	display: inline-block;
    	vertical-align: top;
    	font-style: normal;
    	font-weight: normal;
    	font-variant: normal;
    	text-transform: none;
    	line-height: 30px;
    	color: #fff;
    	opacity: 0;
    	-webkit-font-smoothing: antialiased;
    	-moz-osx-font-smoothing: grayscale;
    	-webkit-transition: opacity 0.3s;
    	transition: opacity 0.3s;
    	-webkit-backface-visibility: hidden;
    	backface-visibility: hidden;
    }
    
    .photostack nav span.current {
    	background: #888;
    	-webkit-transform: scale(1);
    	transform: scale(1);
    }
    
    .photostack nav span.current.flip {
    	-webkit-transform: scale(1) rotateY(-180deg) translateZ(-1px);
    	transform: scale(1) rotateY(-180deg) translateZ(-1px);
    	background: #555;
    }
    
    .photostack nav span.flippable::after {
    	opacity: 1;
    	-webkit-transition-delay: 0.4s;
    	transition-delay: 0.4s;
    }
    
    .js .photostack::before {
    	content: '';
    	position: absolute;
    	width: 100%;
    	height: 100%;
    	background: rgba(0,0,0,0.5);
    	top: 0;
    	left: 0;
    	z-index: 100;
    	-webkit-transition: opacity 0.3s, visibility 0s 0.3s;
    	transition: opacity 0.3s, visibility 0s 0.3s;
    }
    
    .js .photostack-start::before {
    	-webkit-transition: opacity 0.3s;
    	transition: opacity 0.3s;
    }
    
    .js .photostack::after {
    	content: 'View Gallery';
    	font-weight: 400;
    	position: absolute;
    	border: 3px solid #fff;
    	text-align: center;
    	white-space: nowrap;
    	left: 50%;
    	top: 50%;
    	-webkit-transform: translateY(-50%) translateX(-50%);
    	transform: translateY(-50%) translateX(-50%);
    	padding: 10px 20px;
    	color: #fff;
    	text-transform: uppercase;
    	letter-spacing: 1px;
    	cursor: pointer;
    	z-index: 101;
    }
    
    .js .photostack::before,
    .js .photostack::after {
    	opacity: 0;
    	visibility: hidden;
    }
    
    .js .photostack-start::before,
    .js .photostack-start:hover::after,
    .touch .photostack-start::after  {
    	opacity: 1;
    	visibility: visible;
    }
    
    .photostack figure::after {
    	content: '';
    	position: absolute;
    	width: 100%;
    	height: 100%;
    	top: 0;
    	left: 0;
    	visibility: visible;
    	opacity: 1;
    	background: rgba(0,0,0,0.05);
    	-webkit-transition: opacity 0.6s;
    	transition: opacity 0.6s;
    }
    
    
    figure.photostack-current::after {
    	-webkit-transition: opacity 0.6s, visibility 0s 0.6s;
    	transition: opacity 0.6s, visibility 0s 0.6s;
    	opacity: 0;
    	visibility: hidden;
    }
    
    .photostack-transition figure {
    	-webkit-transition: -webkit-transform 0.6s ease-in-out;
    	transition: transform 0.6s ease-in-out;
    }
    
    .photostack-perspective {
    	-webkit-perspective: 1800px;
    	perspective: 1800px;
    }
    
    .photostack-perspective > div,
    .photostack-perspective figure {
    	-webkit-transform-style: preserve-3d;
    	transform-style: preserve-3d;
    }
    
    .photostack-perspective figure,
    .photostack-perspective figure div {
    	-webkit-backface-visibility: hidden;
    	backface-visibility: hidden;
    }
    
    .photostack-perspective figure.photostack-flip {
    	-webkit-transform-origin: 0% 50%;
    	transform-origin: 0% 50%;
    }
    
    .csstransformspreserve3d figure.photostack-flip .photostack-back {
    	-webkit-transform: rotateY(180deg);
    	transform: rotateY(180deg);
    	display: block;
    }
    
    .no-csstransformspreserve3d figure.photostack-showback .photostack-back {
    	display: block;
    }
    
    .no-js .photostack figure {
    	box-shadow: -2px 2px 0 rgba(0,0,0,0.05);
    }
    
    .no-js .photostack figure::after {
    	display: none;
    }
    
    .no-js .photostack figure:nth-child(3n) {
    	-webkit-transform: translateX(-10%) rotate(5deg);
    	transform: translateX(-10%) rotate(5deg);
    }
    
    .no-js .photostack figure:nth-child(3n-2) {
    	-webkit-transform: translateY(10%) rotate(-3deg);
    	transform: translateY(10%) rotate(-3deg);
    }
    
    #photostack-1 nav span.current {
    	background: #888;
    	-webkit-transform: scale(0.61);
    	transform: scale(0.61);
    }
    
    #leftArrowGallery {
    	margin-right: 10px;
    }
    #rightArrowGallery {
    	margin-left: 10px;
    }
    #rightArrowGallery i {
    	padding-left: 5px;
    }
    #leftArrowGallery i {
    	padding-right: 5px;
    }
    .btnGallery {
        background-color: #da2c33;
        border: medium none;
        color: #FFFFFF;
        cursor: pointer;
        display: inline-block;
        font: 12px;
        padding: 3px 6px;
        text-decoration: none;
        white-space: nowrap;
    	border-radius: 5px;
    }
    .btnGallery:hover {
    	background-color: #b20a11;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.7.1/modernizr.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/classie/1.0.1/classie.min.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" media="all" type="text/css" rel="stylesheet">
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    
    <section id="photostack-1" class="photostack photostack-start">
    <div>
    					<figure>
    						<a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/5.jpg" alt="img05"/></a>
    						<figcaption>
    							<h2 class="photostack-title">Speed Racer</h2>
    						</figcaption>
    					</figure>
    					<figure>
    						<a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/2.jpg" alt="img02"/></a>
    						<figcaption>
    							<h2 class="photostack-title">Happy Days</h2>
    						</figcaption>
    					</figure>
    					<figure>
    						<a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/3.jpg" alt="img03"/></a>
    						<figcaption>
    							<h2 class="photostack-title">Beautywood</h2>
    						</figcaption>
    					</figure>
    					<figure>
    						<a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/1.jpg" alt="img01"/></a>
    						<figcaption>
    							<h2 class="photostack-title">Serenity Beach</h2>
    						</figcaption>
    					</figure>
    					<figure>
    						<a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/4.jpg" alt="img04"/></a>
    						<figcaption>
    							<h2 class="photostack-title">Heaven of time</h2>
    						</figcaption>
    					</figure>
    					<figure>
    						<a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/6.jpg" alt="img06"/></a>
    						<figcaption>
    							<h2 class="photostack-title">Forever this</h2>
    						</figcaption>
    					</figure>
    					<figure>
    						<a href="#" class="photostack-img"><img src="https://tympanus.net/Development/ScatteredPolaroidsGallery/img/7.jpg" alt="img07"/></a>
    						<figcaption>
    							<h2 class="photostack-title">Lovely Green</h2>
    						</figcaption>
    					</figure>
    				</div>
            
    		<div id="imageControls">
    			<button id="leftArrowGallery" class="btnGallery"><i class="fa fa-chevron-left"></i></button>
    			<button id="rightArrowGallery" class="btnGallery"><i class="fa fa-chevron-right"></i></button>
    		</div>
    </section>

    【讨论】:

    • 不客气,雷克斯。了解我的问题也很有趣! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多