jQuery網(wǎng)頁選項卡插件rTabs用法實例分析
本文實例講述了jQuery網(wǎng)頁選項卡插件rTabs用法。分享給大家供大家參考。具體如下:
這里介紹jQuery網(wǎng)頁選項卡插件rTabs用法,一共演示了4種TAB選項卡樣式,第一種:默認樣式:自動運行、無動畫效果、Hover事件;第二種:自動運行、向上滾動、支持Hover事件的TAB選項卡菜單;第三種:自動運行、漸入淡出、支持Hover事件的選項卡;第四種:自動運行、向左滾動、點擊事件的網(wǎng)頁選項卡,選一個你喜歡的放在你的網(wǎng)站吧。
先來看看運行效果截圖:
在線演示地址如下:
http://demo.jb51.net/js/2015/jquery-rTabs-web-tab-cha-codes/
具體代碼如下:
<!DOCTYPE html> <html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jQuery - rTabs選項卡插件</title> <head> <script id="jquery_172" type="text/javascript" class="library" src="jquery-1.6.2.min.js"></script> <script type="text/javascript"> (function($){ $.fn.rTabs = function(options){ //默認值 var defaultVal = { btnClass:'.j-tab-nav', /*按鈕的父級Class*/ conClass:'.j-tab-con', /*內(nèi)容的父級Class*/ bind:'hover', /*事件參數(shù) click,hover*/ animation:'0', /*動畫方向 left,up,fadein,0 為無動畫*/ speed:300, /*動畫運動速度*/ delay:200, /*Tab延遲速度*/ auto:true, /*是否開啟自動運行 true,false*/ autoSpeed:3000 /*自動運行速度*/ }; //全局變量 var obj = $.extend(defaultVal, options), evt = obj.bind, btn = $(this).find(obj.btnClass), con = $(this).find(obj.conClass), anim = obj.animation, conWidth = con.width(), conHeight = con.height(), len = con.children().length, sw = len * conWidth, sh = len * conHeight, i = 0, len,t,timer; return this.each(function(){ //判斷動畫方向 function judgeAnim(){ var w = i * conWidth, h = i * conHeight; btn.children().removeClass('current').eq(i).addClass('current'); switch(anim){ case '0': con.children().hide().eq(i).show(); break; case 'left': con.css({position:'absolute',width:sw}).children().css({float:'left',display:'block'}).end().stop().animate({left:-w},obj.speed); break; case 'up': con.css({position:'absolute',height:sh}).children().css({display:'block'}).end().stop().animate({top:-h},obj.speed); break; case 'fadein': con.children().hide().eq(i).fadeIn(); break; } } //判斷事件類型 if(evt == "hover"){ btn.children().hover(function(){ var j = $(this).index(); function s(){ i = j; judgeAnim(); } timer=setTimeout(s,obj.delay); }, function(){ clearTimeout(timer); }) }else{ btn.children().bind(evt,function(){ i = $(this).index(); judgeAnim(); }) } //自動運行 function startRun(){ t = setInterval(function(){ i++; if(i>=len){ switch(anim){ case 'left': con.stop().css({left:conWidth}); break; case 'up': con.stop().css({top:conHeight}); } i=0; } judgeAnim(); },obj.autoSpeed) } //如果自動運行開啟,調(diào)用自動運行函數(shù) if(obj.auto){ $(this).hover(function(){ clearInterval(t); },function(){ startRun(); }) startRun(); } }) } })(jQuery); </script> <script type="text/javascript"> $(function() { $("#tab").rTabs(); $("#tab2").rTabs({ bind : 'click', animation : 'left' }); $("#tab3").rTabs({ bind : 'hover', animation : 'up' }); $("#tab4").rTabs({ bind : 'hover', animation : 'fadein' }); }) </script> <style> body{background:#fff;}h2{width: 400px;margin: 0 auto 10px auto;font-size: 18px;font-family: "微軟雅黑";color: #333;}.tab{position: relative;width: 400px;height: 230px;overflow: hidden;margin: 0 auto 20px auto;font-family: Arial;}.tab-nav{height: 30px;overflow: hidden;background: #f5f5f5;}.tab-nav a{display: block;float: left;width: 80px;height: 30px;line-height: 30px;text-align: center;text-decoration: none;color: #999;}.tab-nav a.current{background: #80b600;color: #fff;}.tab-con{position: relative;width: 400px;height: 200px;overflow: hidden;background: #80b600;}.tab-con-item{display: none;width: 400px;height: 180px;line-height: 180px;text-align: center;color: #fff;} </style> </head> <body> <h1>如果初次打開網(wǎng)頁運行有錯誤看不到效果,請按F5或刷新網(wǎng)頁重新載入即可。</h1></br> <h2>默認樣式:自動運行、無動畫效果、Hover事件</h2> <div class="tab" id="tab"> <div class="tab-nav j-tab-nav"> <a href="javascript:void(0);" class="current">Tab1</a> <a href="javascript:void(0);">Tab2</a> <a href="javascript:void(0);">Tab3</a> <a href="javascript:void(0);">Tab4</a> <a href="javascript:void(0);">Tab5</a> </div> <div class="tab-con"> <div class="j-tab-con"> <div class="tab-con-item" style="display:block;">111111</div> <div class="tab-con-item">222222</div> <div class="tab-con-item">333333</div> <div class="tab-con-item">444444</div> <div class="tab-con-item">555555</div> </div> </div> </div> <h2>自動運行、向左滾動、點擊事件</h2> <div class="tab" id="tab2"> <div class="tab-nav j-tab-nav"> <a href="javascript:void(0);" class="current">Tab1</a> <a href="javascript:void(0);">Tab2</a> <a href="javascript:void(0);">Tab3</a> <a href="javascript:void(0);">Tab4</a> <a href="javascript:void(0);">Tab5</a> </div> <div class="tab-con"> <div class="j-tab-con"> <div class="tab-con-item" style="display:block;">111111</div> <div class="tab-con-item">222222</div> <div class="tab-con-item">333333</div> <div class="tab-con-item">444444</div> <div class="tab-con-item">555555</div> </div> </div> </div> <h2>自動運行、向上滾動、Hover事件</h2> <div class="tab" id="tab3"> <div class="tab-nav j-tab-nav"> <a href="javascript:void(0);" class="current">Tab1</a> <a href="javascript:void(0);">Tab2</a> <a href="javascript:void(0);">Tab3</a> <a href="javascript:void(0);">Tab4</a> <a href="javascript:void(0);">Tab5</a> </div> <div class="tab-con"> <div class="j-tab-con"> <div class="tab-con-item" style="display:block;">111111</div> <div class="tab-con-item">222222</div> <div class="tab-con-item">333333</div> <div class="tab-con-item">444444</div> <div class="tab-con-item">555555</div> </div> </div> </div> <h2>自動運行、漸入、Hover事件</h2> <div class="tab" id="tab4"> <div class="tab-nav j-tab-nav"> <a href="javascript:void(0);" class="current">Tab1</a> <a href="javascript:void(0);">Tab2</a> <a href="javascript:void(0);">Tab3</a> <a href="javascript:void(0);">Tab4</a> <a href="javascript:void(0);">Tab5</a> </div> <div class="tab-con"> <div class="j-tab-con"> <div class="tab-con-item" style="display:block;">111111</div> <div class="tab-con-item">222222</div> <div class="tab-con-item">333333</div> <div class="tab-con-item">444444</div> <div class="tab-con-item">555555</div> </div> </div> </div> </body> </html>
希望本文所述對大家的jquery程序設(shè)計有所幫助。
- jQuery實現(xiàn)的Tab滑動選項卡及圖片切換(多種效果)小結(jié)
- jquery實現(xiàn)經(jīng)典的淡入淡出選項卡效果代碼
- jQuery實現(xiàn)仿騰訊迷你首頁選項卡效果代碼
- jquery實現(xiàn)超簡潔的TAB選項卡效果代碼
- jQuery實現(xiàn)滾動切換的tab選項卡效果代碼
- jquery插件tytabs.jquery.min.js實現(xiàn)漸變TAB選項卡效果
- jQuery實現(xiàn)tab選項卡效果的方法
- jQuery封裝的tab選項卡插件分享
- jquery實現(xiàn)標簽支持圖文排列帶上下箭頭按鈕的選項卡
- jQuery簡單實現(xiàn)網(wǎng)頁選項卡特效
- 基于jQuery實現(xiàn)的仿百度首頁滑動選項卡效果代碼
相關(guān)文章
jQuery懸停文字提示框插件jquery.tooltipster.js用法示例【附demo源碼下載】
這篇文章主要介紹了jQuery懸停文字提示框插件jquery.tooltipster.js用法,涉及jQuery文字提示框插件的引入與調(diào)用實現(xiàn)技巧,非常簡單實用,需要的朋友可以參考下2016-07-07JQuery的read函數(shù)與js的onload不同方式實現(xiàn)
JQuery的read函數(shù)與js的onload,想必大家對這兩個方法都有所熟悉吧,接下來介紹一個實例用以上兩種方法各自實現(xiàn),感興趣的你可不要錯過了哈,希望可以幫助到你2013-03-03jQuery選擇器簡明總結(jié)(含用法實例,一目了然)
jQuery 選擇器一直是 jquery 最神秘,最強大的一部分,當然也是整個 jquery 里面非常基礎(chǔ)的2014-04-04jQuery模板技術(shù)和數(shù)據(jù)綁定實現(xiàn)代碼
如果你用過ASP.NET的數(shù)據(jù)綁定控件,也用過ASP或者JSP里那種通過輸出HTML元素在頁面上顯示數(shù)據(jù)的方法,你就知道ASP.NET數(shù)據(jù)綁定控件有多么方便。如果能夠?qū)⑼瑯拥墓δ茉跒g覽器端用HTML和JavaScript實現(xiàn),那該是多少美妙的事情。2010-05-05