$(document).ready(function() { /* ======= Blog Featured Post Slideshow - Flexslider ======= */ $('.blog-slider').flexslider({ animation: "fade", slideshowSpeed: 3000 }); $('.new-slider').flexslider({ animation: "fade", slideshowSpeed: 3000 }); $('.long-slider').flexslider({ animation: "fade", slideshowSpeed: 3000 }); /* ======= Blog page masonry ======= */ /* Ref: http://desandro.github.io/masonry/index.html */ var $container = $('#blog-mansonry'); $container.imagesLoaded(function(){ $container.masonry({ itemSelector : '.post' }); }); /* ======= Blog page searchbox ======= */ /* Ref: http://thecodeblock.com/expanding-search-bar-with-jquery-tutroial/ */ var submitIcon = $('.searchbox-icon'); var inputBox = $('.searchbox-input'); var searchBox = $('.searchbox'); var isOpen = false; submitIcon.on('click', function(){ if(isOpen === false){ searchBox.addClass('searchbox-open'); inputBox.focus(); isOpen = true; } else { searchBox.removeClass('searchbox-open'); inputBox.focusout(); isOpen = false; } }); submitIcon.mouseup(function(){ return false; }); searchBox.mouseup(function(){ return false; }); $(document).mouseup(function(){ if(isOpen === true){ $('.searchbox-icon').css('display','block'); submitIcon.click(); } }); function buttonUp(){ var inputVal = $('.searchbox-input').val(); inputVal = $.trim(inputVal).length; if( inputVal !== 0){ $('.searchbox-icon').css('display','none'); } else { $('.searchbox-input').val(''); $('.searchbox-icon').css('display','block'); } } inputBox.keyup(function() { buttonUp(); }); //Make sure the "Go" button is not shown when resize the browser window from mobile to desktop $(window).resize(function(){ $('.searchbox-icon').css('display','block'); searchBox.removeClass('searchbox-open'); }); }); /** * 绔嬩綋杞挱 */ (function($){ var Caroursel = function (caroursel){ var self = this; this.caroursel = caroursel; this.posterList = caroursel.find(".poster-list"); this.posterItems = caroursel.find(".poster-item"); this.firstPosterItem = this.posterItems.first(); this.lastPosterItem = this.posterItems.last(); this.prevBtn = this.caroursel.find(".poster-prev-btn"); this.nextBtn = this.caroursel.find(".poster-next-btn"); //脛卢脠脧虏脦脢媒 this.setting = { "width":"1000", "height":"270", "posterWidth":"640", "posterHeight":"270", "scale":"0.8", "speed":"1000", "isAutoplay":"true", "dealy":"1000" } //脳脭露篓脪氓虏脦脢媒脫毛脛卢脠脧虏脦脢媒潞脧虏垄 $.extend(this.setting,this.getSetting()) //脡猫脰脙碌脷脪禄脰隆脦禄脰脙 this.setFirstPosition(); //脡猫脰脙脢拢脫脿脰隆碌脛脦禄脰脙 this.setSlicePosition(); //脨媒脳陋 this.rotateFlag = true; this.prevBtn.bind("click",function(){ if(self.rotateFlag){ self.rotateFlag = false; self.rotateAnimate("left") } }); this.nextBtn.bind("click",function(){ if(self.rotateFlag){ self.rotateFlag = false; self.rotateAnimate("right") } }); if(this.setting.isAutoplay){ this.autoPlay(); this.caroursel.hover(function(){clearInterval(self.timer)},function(){self.autoPlay()}) } }; Caroursel.prototype = { autoPlay:function(){ var that = this; this.timer = window.setInterval(function(){ that.prevBtn.click(); },that.setting.dealy) }, rotateAnimate:function(type){ var that = this; var zIndexArr = []; if(type == "left"){//脧貌脳贸脪脝露炉 this.posterItems.each(function(){ var self = $(this), prev = $(this).next().get(0)?$(this).next():that.firstPosterItem, width = prev.css("width"), height = prev.css("height"), zIndex = prev.css("zIndex"), opacity = prev.css("opacity"), left = prev.css("left"), top = prev.css("top"); zIndexArr.push(zIndex); self.animate({ "width":width, "height":height, "left":left, "opacity":opacity, "top":top, },that.setting.speed,function(){ that.rotateFlag = true; }); }); this.posterItems.each(function(i){ $(this).css("zIndex",zIndexArr[i]); }); } if(type == "right"){//脧貌脫脪脪脝露炉 this.posterItems.each(function(){ var self = $(this), next = $(this).prev().get(0)?$(this).prev():that.lastPosterItem, width = next.css("width"), height = next.css("height"), zIndex = next.css("zIndex"), opacity = next.css("opacity"), left = next.css("left"), top = next.css("top"); zIndexArr.push(zIndex); self.animate({ "width":width, "height":height, "left":left, "opacity":opacity, "top":top, },that.setting.speed,function(){ that.rotateFlag = true; }); }); this.posterItems.each(function(i){ $(this).css("zIndex",zIndexArr[i]); }); } }, setFirstPosition:function(){ this.caroursel.css({"width":this.setting.width,"height":this.setting.height}); this.posterList.css({"width":this.setting.width,"height":this.setting.height}); var width = (this.setting.width - this.setting.posterWidth) / 2; //脡猫脰脙脕陆赂枚掳麓脜楼碌脛脩霉脢陆 this.prevBtn.css({"width":width , "height":this.setting.height,"zIndex":Math.ceil(this.posterItems.size()/2)}); this.nextBtn.css({"width":width , "height":this.setting.height,"zIndex":Math.ceil(this.posterItems.size()/2)}); this.firstPosterItem.css({ "width":this.setting.posterWidth, "height":this.setting.posterHeight, "left":width, "zIndex":Math.ceil(this.posterItems.size()/2), "top":this.setVertialType(this.setting.posterHeight) }); }, setSlicePosition:function(){ var _self = this; var sliceItems = this.posterItems.slice(1), level = Math.floor(this.posterItems.length/2), leftItems = sliceItems.slice(0,level), rightItems = sliceItems.slice(level), posterWidth = this.setting.posterWidth, posterHeight = this.setting.posterHeight, Btnwidth = (this.setting.width - this.setting.posterWidth) / 2, gap = Btnwidth/level, containerWidth = this.setting.width; //脡猫脰脙脳贸卤脽脰隆碌脛脦禄脰脙 var i = 1; var leftWidth = posterWidth; var leftHeight = posterHeight; var zLoop1 = level; leftItems.each(function(index,item){ leftWidth = posterWidth * _self.setting.scale; leftHeight = posterHeight*_self.setting.scale; $(this).css({ "width":leftWidth, "height":leftHeight, "left": Btnwidth - i*gap, "zIndex":zLoop1--, "opacity":1/(i+1), "top":_self.setVertialType(leftHeight) }); i++; }); //脡猫脰脙脫脪脙忙脰隆碌脛脦禄脰脙 var j = level; var zLoop2 = 1; var rightWidth = posterWidth; var rightHeight = posterHeight; rightItems.each(function(index,item){ var rightWidth = posterWidth * _self.setting.scale; var rightHeight = posterHeight*_self.setting.scale; $(this).css({ "width":rightWidth, "height":rightHeight, "left": containerWidth -( Btnwidth - j*gap + rightWidth), "zIndex":zLoop2++, "opacity":1/(j+1), "top":_self.setVertialType(rightHeight) }); j--; }); }, getSetting:function(){ var settting = this.caroursel.attr("data-setting"); if(settting.length > 0){ return $.parseJSON(settting); }else{ return {}; } }, setVertialType:function(height){ var algin = this.setting.algin; if(algin == "top") { return 0 }else if(algin == "middle"){ return (this.setting.posterHeight - height) / 2 }else if(algin == "bottom"){ return this.setting.posterHeight - height }else { return (this.setting.posterHeight - height) / 2 } } } Caroursel.init = function (caroursels){ caroursels.each(function(index,item){ new Caroursel($(this)); }) ; }; window["Caroursel"] = Caroursel; })(jQuery)