jQuery實(shí)現(xiàn)帶滾動(dòng)導(dǎo)航效果的全屏滾動(dòng)相冊(cè)實(shí)例
本文實(shí)例講述了jQuery實(shí)現(xiàn)帶滾動(dòng)導(dǎo)航效果的全屏滾動(dòng)相冊(cè)。分享給大家供大家參考。具體如下:
運(yùn)行效果圖如下:
主要代碼如下:
$(function() { //加載時(shí)的圖片 var $loader= $('#st_loading'); //獲取的ul元素 var $list= $('#st_nav'); //當(dāng)前顯示的圖片 var $currImage = $('#st_main').children('img:first'); //加載當(dāng)前的圖片 //同時(shí)顯示導(dǎo)航的項(xiàng) $('<img>').load(function(){ $loader.hide(); $currImage.fadeIn(3000); //滑出導(dǎo)航 setTimeout(function(){ $list.animate({'left':'0px'},500); }, 1000); }).attr('src',$currImage.attr('src')); //計(jì)算出將被顯示的略縮圖所在的div元素的寬度 buildThumbs(); function buildThumbs(){ $list.children('li.album').each(function(){ var $elem = $(this); var $thumbs_wrapper = $elem.find('.st_thumbs_wrapper'); var $thumbs = $thumbs_wrapper.children(':first'); //每張略縮圖占有180像素的寬度和3像素的間距(margin) var finalW = $thumbs.find('img').length * 183; $thumbs.css('width',finalW + 'px'); //是這元素具有滾動(dòng)性 makeScrollable($thumbs_wrapper,$thumbs); }); } //點(diǎn)擊菜單項(xiàng)目的時(shí)候(向上向下箭頭切換) //使略縮圖的div層顯示和隱藏當(dāng)前的 //打開菜單(如果有的話) $list.find('.st_arrow_down').live('click',function(){ var $this = $(this); hideThumbs(); $this.addClass('st_arrow_up').removeClass('st_arrow_down'); var $elem = $this.closest('li'); $elem.addClass('current').animate({'height':'170px'},200); var $thumbs_wrapper = $this.parent().next(); $thumbs_wrapper.show(200); }); $list.find('.st_arrow_up').live('click',function(){ var $this = $(this); $this.addClass('st_arrow_down').removeClass('st_arrow_up'); hideThumbs(); }); //點(diǎn)擊略縮圖,改變大的圖片 $list.find('.st_thumbs img').bind('click',function(){ var $this = $(this); $loader.show(); $('<img class="st_preview"/>').load(function(){ var $this = $(this); var $currImage = $('#st_main').children('img:first'); $this.insertBefore($currImage); $loader.hide(); $currImage.fadeOut(2000,function(){ $(this).remove(); }); }).attr('src',$this.attr('alt')); }).bind('mouseenter',function(){ $(this).stop().animate({'opacity':'1'}); }).bind('mouseleave',function(){ $(this).stop().animate({'opacity':'0.7'}); }); //隱藏當(dāng)前已經(jīng)打開了的菜單的函數(shù) function hideThumbs(){ $list.find('li.current') .animate({'height':'50px'},400,function(){ $(this).removeClass('current'); }) .find('.st_thumbs_wrapper') .hide(200) .andSelf() .find('.st_link span') .addClass('st_arrow_down') .removeClass('st_arrow_up'); } //是當(dāng)前的略縮圖div層滾動(dòng) //當(dāng)鼠標(biāo)移至菜單層的時(shí)候會(huì)自動(dòng)地進(jìn)行滾動(dòng) function makeScrollable($outer, $inner){ var extra = 800; //獲取菜單的寬度 var divWidth = $outer.width(); //移除滾動(dòng)條 $outer.css({ overflow: 'hidden' }); //查找容器上的最后一張圖片 var lastElem = $inner.find('img:last'); $outer.scrollLeft(0); //當(dāng)用戶鼠標(biāo)離開菜單的時(shí)候 $outer.unbind('mousemove').bind('mousemove',function(e){ var containerWidth = lastElem[0].offsetLeft + lastElem.outerWidth() + 2*extra; var left = (e.pageX - $outer.offset().left) * (containerWidth-divWidth) / divWidth - extra; $outer.scrollLeft(left); }); } });
希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。
相關(guān)文章
Jquery實(shí)現(xiàn)無縫向上循環(huán)滾動(dòng)列表的特效
今天小編就為大家分享一篇關(guān)于Jquery實(shí)現(xiàn)無縫向上循環(huán)滾動(dòng)列表的特效,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-02-02jQuery noConflict() 方法用法實(shí)例分析
這篇文章主要介紹了jQuery noConflict() 方法用法,結(jié)合實(shí)例形式分析了jQuery noConflict() 方法基本功能、用法及操作注意事項(xiàng),需要的朋友可以參考下2020-05-05簡(jiǎn)單的jquery左側(cè)導(dǎo)航欄和頁(yè)面選中效果
這篇文章主要介紹一個(gè)簡(jiǎn)單的jquery左側(cè)導(dǎo)航欄和頁(yè)面選中效果,此功能需引用jquery,需要的朋友可以參考下2014-08-08jquery如何把數(shù)組變?yōu)樽址畟鞯椒?wù)端并處理
這篇文章主要介紹了jquery如何把數(shù)組變?yōu)樽址畟鞯椒?wù)端并處理,需要的朋友可以參考下2014-04-04Jquery如何實(shí)現(xiàn)點(diǎn)擊時(shí)高亮顯示代碼
點(diǎn)擊時(shí)高亮顯示代碼的實(shí)現(xiàn)方法有很多,下面的示例使用jquery來實(shí)現(xiàn),需要的朋友可以了解下2014-01-01