Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="pictureSlider poster-main" data-setting='{
                                                                                    "width":1000,
                                                                                    "height":270,
                                                                                    "posterWidth":640,
                                                                                    "posterHeight":270,
                                                                                    "scale":0.8,
                                                                                    "autoPlay":true,
                                                                                    "delay":2000,
                                                                                    "speed":300
																					}'>
	<div class="poster-btn poster-prev-btn"></div>
    <ul class="poster-list">
    	<li class="poster-item"><a href="#"><img src="https://unsplash.it/640/270?image=1014" width="100%" height="100%"></a></li>
        <li class="poster-item"><a href="#"><img src="https://unsplash.it/640/270?image=1013" width="100%" height="100%"></a></li>
        <li class="poster-item"><a href="#"><img src="https://unsplash.it/640/270?image=1012" width="100%" height="100%"></a></li>
        <li class="poster-item"><a href="#"><img src="https://unsplash.it/640/270?image=1011" width="100%" height="100%"></a></li>
        <li class="poster-item"><a href="#"><img src="https://unsplash.it/640/270?image=1010" width="100%" height="100%"></a></li>
        <li class="poster-item"><a href="#"><img src="https://unsplash.it/640/270?image=1009" width="100%" height="100%"></a></li>
        <li class="poster-item"><a href="#"><img src="https://unsplash.it/640/270?image=1008" width="100%" height="100%"></a></li>
        <li class="poster-item"><a href="#"><img src="https://unsplash.it/640/270?image=1009" width="100%" height="100%"></a></li>
        <li class="poster-item"><a href="#"><img src="https://unsplash.it/640/270?image=1006" width="100%" height="100%"></a></li>
    </ul>
    <div class="poster-btn poster-next-btn"></div>
</div>
              
            
!

CSS

              
                /*йЗНзљЃ*/
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{margin:0;padding:0;}
table{border-collapse:collapse;border-spacing:0;}
fieldset,img{border:0;}
address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}
ol,ul{list-style:none;}
caption,th{text-align:left;}
h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}
q:before,q:after{content: ;}
abbr,acronym{border:0;}
.clearfix:after {visibility:hidden;display:block;font-size:0;content:" ";clear:both;height:0;}
.clearfix {zoom:1;}	
/*жЧЛиљђжЬ®й©ђењЕи¶Бж†ЈеЉП*/
.poster-main{ position:relative;width:800px;height:270px;}
.poster-main a,.poster-main img{display:block;}
.poster-main .poster-list{width:800px;height:270px;}
.poster-main .poster-list .poster-item{ position:absolute;left:0;top:0;}
.poster-main .poster-btn{ position:absolute;top:0;width:100px;height:270px; z-index:10; cursor:pointer;  opacity:0.8}
.poster-main .poster-prev-btn{left:0; background: url(btn_l.png) no-repeat center center;}
.poster-main .poster-next-btn{right:0; background: url(btn_r.png) no-repeat center center;}

              
            
!

JS

              
                ;(function($){

	var Carousel = function(poster){
		var self = this;
		//дњЭе≠ШеНХдЄ™жЧЛиљђжЬ®й©ђеѓєи±°
		this.poster = poster;
		this.posterItemMain = poster.find("ul.poster-list");
		this.nextBtn = poster.find("div.poster-next-btn");
		this.prevBtn = poster.find("div.poster-prev-btn");
		this.posterItems = poster.find("li.poster-item");
		if( this.posterItems.size()%2 == 0 ){
			this.posterItemMain.append( this.posterItems.eq(0).clone() );
			this.posterItems = this.posterItemMain.children();
		};
		this.posterFirstItem = this.posterItems.first();
		this.posterLastItem = this.posterItems.last();
		this.rotateFlag = true;
		//йїШиЃ§йЕНзљЃеПВжХ∞
		this.setting = {
			"width" : 1000,			//еєїзБѓзЙЗзЪДеЃљеЇ¶
			"height" : 270,			//еєїзБѓзЙЗзЪДйЂШеЇ¶
			"posterWidth" : 640,	//еєїзБѓзЙЗзђђдЄАеЄІзЪДеЃљеЇ¶
			"posterHeight" : 270,	//еєїзБѓзЙЗзђђдЄАеЄІзЪДйЂШеЇ¶
			"scale" : 0.9,			//иЃ∞ељХжШЊз§ЇжѓФдЊЛеЕ≥з≥ї
			"speed" : 500,
			"autoPlay" : false,
			"delay" : 5000,
			"verticalAlign" : "middle" //top bottom
		};
		$.extend( this.setting,this.getSetting() );
		
		//иЃЊзљЃйЕНзљЃеПВжХ∞еАЉ
		this.setSettingValue();
		//еИЭеІЛеМЦеєїзБѓзЙЗдљНзљЃ
		this.setPosterPos();
		//еЈ¶жЧЛиљђжМЙйТЃ
		this.nextBtn.click(function(){
			if(self.rotateFlag){
				self.rotateFlag = false;
				self.carouseRotate("left");
			};
		});
		//еП≥жЧЛиљђжМЙйТЃ
		this.prevBtn.click(function(){
			if(self.rotateFlag){
				self.rotateFlag = false;
				self.carouseRotate("right");
			};
		});
		//жШѓеР¶еЉАеРѓиЗ™еК®жТ≠жФЊ
		if(this.setting.autoPlay){
			this.autoPlay();
			this.poster.hover( function(){
				//self.timerжШѓsetIntervalзЪДзІНе≠Р
				window.clearInterval(self.timer);
			}, function(){
				self.autoPlay();
			});			
		};
	};
	Carousel.prototype = {
		autoPlay:function(){
			var self = this;
			this.timer = window.setInterval( function(){
				self.nextBtn.click();
			}, this.setting.delay );
		},

		//жЧЛиљђ
		carouseRotate:function(dir){
			var _this_  = this;
			var zIndexArr = [];
			//еЈ¶жЧЛиљђ
			if(dir === "left"){
				this.posterItems.each(function(){
					var self = $(this),
						prev = self.prev().get(0)?self.prev():_this_.posterLastItem,
						width = prev.width(),
						height =prev.height(),
						opacity = prev.css("opacity"),
						left = prev.css("left"),
						top = prev.css("top"),
						zIndex = prev.css("zIndex");

					zIndexArr.push(zIndex);
					self.animate({
						width :width,
						height :height,
					  //zIndex :zIndex,
					    opacity :opacity,
					    left :left,
					    top :top
					},_this_.setting.speed,function(){
						_this_.rotateFlag = true;
					});
				});
				//zIndexйЬАи¶БеНХзЛђдњЭе≠ШеЖНиЃЊзљЃпЉМйШ≤ж≠ҐеЊ™зОѓжЧґеАЩиЃЊзљЃеЖНеПЦзЪДжЧґеАЩеАЉж∞ЄињЬжШѓжЬАеРОдЄАдЄ™зЪДzindex
				this.posterItems.each(function(i){
					$(this).css("zIndex",zIndexArr[i]);
				});
			}else if(dir === "right"){//еП≥жЧЛиљђ
				this.posterItems .each(function(){
					var self = $(this),
						next = self.next().get(0)?self.next():_this_.posterFirstItem,
						width = next.width(),
						height =next.height(),
						opacity = next.css("opacity"),
						left = next.css("left"),
						top = next.css("top"),
						zIndex = next.css("zIndex");

					zIndexArr.push(zIndex);					
					self.animate({
						width :width,
						height :height,
					  //zIndex :zIndex,
					    opacity :opacity,
					    left :left,
					    top :top
					},_this_.setting.speed,function(){
						_this_.rotateFlag = true;
					});	
				});
				//zIndexйЬАи¶БеНХзЛђдњЭе≠ШеЖНиЃЊзљЃпЉМйШ≤ж≠ҐеЊ™зОѓжЧґеАЩиЃЊзљЃеЖНеПЦзЪДжЧґеАЩеАЉж∞ЄињЬжШѓжЬАеРОдЄАдЄ™зЪДzindex
				this.posterItems.each(function(i){
					$(this).css("zIndex",zIndexArr[i]);
				});
			};
		},
		//иЃЊзљЃеЙ©дљЩзЪДеЄІзЪДдљНзљЃеЕ≥з≥ї
		setPosterPos:function(){
			var self = this,
				sliceItems = this.posterItems.slice(1),
				sliceSize = sliceItems.size()/2,
				rightSlice = sliceItems.slice(0,sliceSize),
				//е≠ШеЬ®еЫЊзЙЗе•ЗеБґжХ∞йЧЃйҐШ
				level = Math.floor(this.posterItems.size()/2),
				leftSlice = sliceItems.slice(sliceSize);
			
			//иЃЊзљЃеП≥иЊєеЄІзЪДдљНзљЃеЕ≥з≥їеТМеЃљеЇ¶йЂШеЇ¶top
			var firstLeft = (this.setting.width - this.setting.posterWidth)/2;
			var rw = this.setting.posterWidth,
				fixOffsetLeft = firstLeft + rw,
				rh = this.setting.posterHeight,
				gap = ((this.setting.width - this.setting.posterWidth)/2)/level;
			
			//иЃЊзљЃеП≥иЊєдљНзљЃеЕ≥з≥ї
			rightSlice.each(function(i){
				level--;
				rw = rw * self.setting.scale;
				rh = rh * self.setting.scale;
				var j = i;
				$(this).css({
					zIndex :level,
					width :rw,
					height :rh,
					opacity :1/(++j),
					left :fixOffsetLeft+(++i)*gap - rw,
					top :self.setVerticalAlign(rh)
				});
			});

			//иЃЊзљЃеЈ¶иЊєзЪДдљНзљЃеЕ≥з≥ї
			var lw = rightSlice.last().width(),
				lh  =rightSlice.last().height(),
				oloop = Math.floor(this.posterItems.size()/2);
			leftSlice.each(function(i){
				$(this).css({
					zIndex:i,
					width:lw,
					height:lh,
					opacity:1/oloop,
					left:i*gap,
					top:self.setVerticalAlign(lh)
				});
				lw = lw/self.setting.scale;
				lh = lh/self.setting.scale;
				oloop--;
			});
		},
	
		//иЃЊзљЃеЮВзЫіжОТеИЧеѓєйљР
		setVerticalAlign:function(height){
			var verticalType  = this.setting.verticalAlign,
				top = 0;
			if(verticalType === "middle"){
				top = (this.setting.height-height)/2;
			}else if(verticalType === "top"){
				top = 0;
			}else if(verticalType === "bottom"){
				top = this.setting.height-height;
			}else{
				top = (this.setting.height-height)/2;
			};
			return top;
		},

		//иЃЊзљЃйЕНзљЃеПВжХ∞еАЉеОїжОІеИґеЯЇжЬђзЪДеЃљеЇ¶йЂШеЇ¶гАВгАВгАВ
		setSettingValue:function(){
			this.poster.css({
				width:this.setting.width,
				height:this.setting.height
			});
			this.posterItemMain.css({
				width:this.setting.width,
				height:this.setting.height
			});
			//иЃ°зЃЧдЄКдЄЛеИЗжНҐжМЙйТЃзЪДеЃљеЇ¶
			var w = (this.setting.width-this.setting.posterWidth)/2;
			//иЃЊзљЃеИЗжНҐжМЙйТЃзЪДеЃљйЂШпЉМе±ВзЇІеЕ≥з≥ї
			this.nextBtn.css({
				width:w,
				height:this.setting.height,
				zIndex:Math.ceil(this.posterItems.size()/2)
			});
			this.prevBtn.css({
				width:w,
				height:this.setting.height,
				zIndex:Math.ceil(this.posterItems.size()/2)
			});			
			this.posterFirstItem.css({
				width:this.setting.posterWidth,
				height:this.setting.posterHeight,
				left:w,
				top:0,
				zIndex:Math.floor(this.posterItems.size()/2)
			});
		},

		//иОЈеПЦдЇЇеЈ•йЕНзљЃеПВжХ∞
		getSetting:function(){			
			var setting = this.poster.attr("data-setting");
			if(setting && setting != ""){
				return $.parseJSON(setting);
			}else{
				return {};
			};
		}	
	};

	Carousel.init = function(posters){
		var _this_ = this;
		posters.each(function(){
			console.log("halo Louis;")
			new  _this_($(this));
		});
	};

	//жМВиљљеИ∞windowдЄЛ
	window["Carousel"] = Carousel;

})(jQuery);





/*initial*/
$(function(){
	Carousel.init($(".pictureSlider"));
});
              
            
!
999px

Console