本文實例講述了jQuery實現點擊后標記當前菜單位置(背景高亮菜單)效果。分享給大家供大家參考。具體如下:
這是一款jquery菜單特效,點擊后高亮背景,個性的菜單特效。網上見到比較多的菜單了,不過像這樣這么簡單的方法來實現卻不多見,本菜單整體簡潔,點擊導航欄上的任意菜單項后,該菜單項的背景變成黑色,并且鼠標移走后,仍然固定保持黑色,記住了菜單的位置。
運行效果如下圖所示:
在線演示地址如下:
http://demo.VeVB.COm/js/2015/jquery-menu-set-focus-style-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><title>jquery點擊后高亮背景的菜單特效</title><style>*{ margin:0; padding:0; list-style:none;}body{ font:normal 14px/24px 'MicroSoft YaHei';}.cotrs{ width:960px; height:32px; line-height:32px; background:#999; margin:0 auto;}.cotrs a{ height:32px; line-height:32px; color:#fff; text-decoration:none; padding:0px 10px; display:block; float:left;}.cotrs a:hover{ text-decoration:none; background:#000;}.cotrs a.thisclass{text-decoration:none; background:#000;}</style></head><body><br><br><br><div class="cotrs"><a href='javascript:' class="thisclass">首頁</a><a href='javascript:'>菜單導航</a><a href='javascript:'>時間日期</a><a href='javascript:'>焦點圖</a><a href='javascript:'>tab標簽</a><a href='javascript:'>jquery特效</a><a href='javascript:'>在線客服</a><a href='javascript:'>廣告代碼</a><a href='javascript:'>相冊代碼</a><a href='javascript:'>圖片特效</a><a href='javascript:'>名站特效</a><a href='javascript:'>其他代碼</a><a href='javascript:'>HTML5</a></div><script src="jquery-1.9.1.min.js"></script><script>$(function(){var cotrs = $(".cotrs a");cotrs.click(function(){ $(this).addClass("thisclass").siblings().removeClass("thisclass");});});</script><div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';"></div></body></html>
希望本文所述對大家的jquery程序設計有所幫助。
新聞熱點
疑難解答