本文實例講述了jquery實作左右滑動選單效果碼。分享給大家供大家參考。具體如下:
這裡示範了三種背景顏色左右滑動jquery選單導航效果,IE下有問題,本選單使用了CSS3的部分屬性,因此建議使用火狐或Chrome等瀏覽器來取得最佳效果。當把滑鼠移到選單上的時候,對應選單項目的背景會變化,而且本選單具有圓角的效果。
運作效果截圖如下:
線上示範網址如下:
http://demo.jb51.net/js/2015/jquery-left-right-move-style-menu-codes/
具體程式碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>三种背景颜色左右滑动菜单导航</title> <style> .webwidget_menu_glide{ padding: 5px; -moz-border-radius-topright: 10px; -moz-border-radius-topleft: 10px; -webkit-border-top-left-radius: 10px; -webkit-border-top-right-radius: 10px; -khtml-border-radius-topright: 10px; -khtml-border-radius-topleft: 10px; border-radius-topright: 10px; border-radius-topleft: 10px; -moz-border-radius-bottomright: 10px; -moz-border-radius-bottomleft: 10px; -webkit-border-bottom-left-radius: 10px; -webkit-border-bottom-right-radius: 10px; -khtml-border-radius-bottomright: 10px; -khtml-border-radius-bottomleft: 10px; border-radius-bottomright: 10px; border-radius-bottomleft: 10px; border-radius:10px; } .webwidget_menu_glide .webwidget_menu_glide_sprite{ width: 100px; height: 20px; background-color: fuchsia; position: absolute; -moz-border-radius-topright: 10px; -moz-border-radius-topleft: 10px; -webkit-border-top-left-radius: 10px; -webkit-border-top-right-radius: 10px; -khtml-border-radius-topright: 10px; -khtml-border-radius-topleft: 10px; border-radius-topright: 10px; border-radius-topleft: 10px; -moz-border-radius-bottomright: 10px; -moz-border-radius-bottomleft: 10px; -webkit-border-bottom-left-radius: 10px; -webkit-border-bottom-right-radius: 10px; -khtml-border-radius-bottomright: 10px; -khtml-border-radius-bottomleft: 10px; border-radius-bottomright: 10px; border-radius-bottomleft: 10px; border-radius:10px; } .webwidget_menu_glide ul{ padding: 0px; margin: 0px; font-family:Arial; } .webwidget_menu_glide ul li{ float: left; list-style: none; position: relative; text-align: center; margin-right: 10px; width: 100px; } .webwidget_menu_glide ul li a{ color: black; text-decoration: none; font-weight: bold; } .webwidget_menu_glide ul li ul{ -moz-border-radius-bottomright: 7px; -moz-border-radius-bottomleft: 7px; -webkit-border-bottom-left-radius: 7px; -webkit-border-bottom-right-radius: 7px; -khtml-border-radius-bottomright: 7px; -khtml-border-radius-bottomleft: 7px; border-radius-bottomright: 7px; border-radius-bottomleft: 7px; border-radius:7px; padding-bottom: 5px; position: absolute; z-index: 999999; display: none; } .webwidget_menu_glide ul li ul li{ -moz-border-radius-topright: 0px; -moz-border-radius-topleft: 0px; -webkit-border-top-left-radius: 0px; -webkit-border-top-right-radius: 0px; -khtml-border-radius-topright: 0px; -khtml-border-radius-topleft: 0px; border-radius-topright: 0px; border-radius-topleft: 0px; border-radius:0px; margin: 0px; float: none; border:none; word-wrap:break-word; } .webwidget_menu_glide ul li ul li a{ padding-left: 5px; padding-right: 5px; font-weight: normal; } </style> </link> <script type="text/javascript" src="jquery-1.6.2.min.js"></script> <script type="text/javascript"> (function(a){ a.fn.webwidget_menu_glide=function(p){ var p=p||{}; var f=p&&p.menu_text_size?p.menu_text_size:"12px"; var g=p&&p.menu_text_color?p.menu_text_color:"blue"; var h=p&&p.menu_margin?p.menu_margin:"10px"; var i=p&&p.menu_width?p.menu_width:"100px"; var j=p&&p.menu_height?p.menu_height:"20px"; var k=p&&p.menu_sprite_color?p.menu_sprite_color:"red"; var l=p&&p.menu_background_color?p.menu_background_color:"black"; var m=p&&p.sprite_speed?p.sprite_speed:"fast"; f += "px"; h += "px"; i += "px"; j += "px"; var n=a(this); if(n.children("ul").length==0||n.find("li").length==0){ n.append("Require menu content"); return null } s_m(n.children("ul").children("li"),h,i,j); s_m_t_c(n.find("a"),g,j,f); n.css("background-color",l); if(n.children("ul").children("li").is(".current")){ var o=n.children("ul").children("li").filter(".current").offset() }else{ var o=n.children("ul").children("li:first").offset() } var q=o.left+'px'; s_m_s_c(n.find(".webwidget_menu_glide_sprite"),k,i,j,q); n.children("ul").children("li").hover(function(){ var b=$(this).offset(); var c=b.left+'px'; n.find(".webwidget_menu_glide_sprite").stop().animate({ left:c },m) },function(){ n.find(".webwidget_menu_glide_sprite").stop().animate({ left:q },m) }); n.children("ul").children("li").children("ul").children("li").hover(function(){},function(){}); function s_m_t_c(a,b,c,d){ a.css("color",b); a.css("line-height",c); a.css("font-size",d) } function s_m(a,b,c,d){ style="margin-right:"+b+"; width: "+c+"; height: "+d+";"; a.attr("style",style) } function s_m_s_c(a,b,c,d,e){ a.css("background-color",b); a.css("width",c); a.css("height",d); a.css("left",e) } } })(jQuery); </script> </head> <body> <table width="600"> <tr> <td><h2 id="Demo">Demo1</h2> <br/> <br/> <script language="javascript" type="text/javascript"> $(function() { $("#webwidget_menu_glide1").webwidget_menu_glide({menu_width:"100", menu_height:"30", menu_text_size:"15", menu_text_color:"#FFF", menu_sprite_color:"red", menu_background_color:"#C91A3E", menu_margin:"5", sprite_speed:"normal", container:"webwidget_menu_glide1" }); }); </script> <div id="webwidget_menu_glide1" class="webwidget_menu_glide"> <div class="webwidget_menu_glide_sprite"></div> <ul> <li><a href="#">Home</a></li> <li><a href="#">News</a></li> <li class="current"><a href="#">About</a></li> <li><a href="#">Contact</a></li> <li><a href="#">More...</a></li> </ul> <div style="clear: both"></div> </div></td> </tr> <tr> <td><h2 id="Demo">Demo2</h2> <br/> <br/> <script language="javascript" type="text/javascript"> $(function() { $("#webwidget_menu_glide2").webwidget_menu_glide({menu_width:"100", menu_height:"30", menu_text_size:"15", menu_text_color:"#CCC", menu_sprite_color:"#666", menu_background_color:"#000", menu_margin:"5", sprite_speed:"normal", container:"webwidget_menu_glide2" }); }); </script> <div id="webwidget_menu_glide2" class="webwidget_menu_glide"> <div class="webwidget_menu_glide_sprite"></div> <ul> <li><a href="#">Home</a></li> <li><a href="#">News</a></li> <li class="current"><a href="#">About</a></li> <li><a href="#">Contact</a></li> <li><a href="#">More...</a></li> </ul> <div style="clear: both"></div> </div></td> </tr> <tr> <td><h2 id="Demo">Demo3</h2> <br/> <br/> <script language="javascript" type="text/javascript"> $(function() { $("#webwidget_menu_glide3").webwidget_menu_glide({menu_width:"100", menu_height:"23", menu_text_size:"12", menu_text_color:"#FFF", menu_sprite_color:"#86C7EF", menu_background_color:"#0F67A1", menu_margin:"2", sprite_speed:"normal", container:"webwidget_menu_glide3" }); }); </script> <div id="webwidget_menu_glide3" class="webwidget_menu_glide"> <div class="webwidget_menu_glide_sprite"></div> <ul> <li><a href="#">Home</a></li> <li><a href="#">News</a></li> <li class="current"><a href="#">About</a></li> <li><a href="#">Contact</a></li> <li><a href="#">More...</a></li> </ul> <div style="clear: both"></div> </div></td> </tr> </table> </body> </html>
希望本文所述對大家的jquery程式設計有所幫助。

JavaScript是現代網站的核心,因為它增強了網頁的交互性和動態性。 1)它允許在不刷新頁面的情況下改變內容,2)通過DOMAPI操作網頁,3)支持複雜的交互效果如動畫和拖放,4)優化性能和最佳實踐提高用戶體驗。

C 和JavaScript通過WebAssembly實現互操作性。 1)C 代碼編譯成WebAssembly模塊,引入到JavaScript環境中,增強計算能力。 2)在遊戲開發中,C 處理物理引擎和圖形渲染,JavaScript負責遊戲邏輯和用戶界面。

JavaScript在網站、移動應用、桌面應用和服務器端編程中均有廣泛應用。 1)在網站開發中,JavaScript與HTML、CSS一起操作DOM,實現動態效果,並支持如jQuery、React等框架。 2)通過ReactNative和Ionic,JavaScript用於開發跨平台移動應用。 3)Electron框架使JavaScript能構建桌面應用。 4)Node.js讓JavaScript在服務器端運行,支持高並發請求。

Python更適合數據科學和自動化,JavaScript更適合前端和全棧開發。 1.Python在數據科學和機器學習中表現出色,使用NumPy、Pandas等庫進行數據處理和建模。 2.Python在自動化和腳本編寫方面簡潔高效。 3.JavaScript在前端開發中不可或缺,用於構建動態網頁和單頁面應用。 4.JavaScript通過Node.js在後端開發中發揮作用,支持全棧開發。

C和C 在JavaScript引擎中扮演了至关重要的角色,主要用于实现解释器和JIT编译器。1)C 用于解析JavaScript源码并生成抽象语法树。2)C 负责生成和执行字节码。3)C 实现JIT编译器,在运行时优化和编译热点代码,显著提高JavaScript的执行效率。

JavaScript在現實世界中的應用包括前端和後端開發。 1)通過構建TODO列表應用展示前端應用,涉及DOM操作和事件處理。 2)通過Node.js和Express構建RESTfulAPI展示後端應用。

JavaScript在Web開發中的主要用途包括客戶端交互、表單驗證和異步通信。 1)通過DOM操作實現動態內容更新和用戶交互;2)在用戶提交數據前進行客戶端驗證,提高用戶體驗;3)通過AJAX技術實現與服務器的無刷新通信。

理解JavaScript引擎內部工作原理對開發者重要,因為它能幫助編寫更高效的代碼並理解性能瓶頸和優化策略。 1)引擎的工作流程包括解析、編譯和執行三個階段;2)執行過程中,引擎會進行動態優化,如內聯緩存和隱藏類;3)最佳實踐包括避免全局變量、優化循環、使用const和let,以及避免過度使用閉包。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

禪工作室 13.0.1
強大的PHP整合開發環境

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

SublimeText3漢化版
中文版,非常好用

Atom編輯器mac版下載
最受歡迎的的開源編輯器