Home >Web Front-end >JS Tutorial >jQuery implements secondary CSS menu effect that can be highlighted_jquery

jQuery implements secondary CSS menu effect that can be highlighted_jquery

WBOY
WBOYOriginal
2016-05-16 15:41:181137browse

The example in this article describes jQuery’s implementation of a highlightable secondary CSS menu effect. Share it with everyone for your reference. The details are as follows:

Here, the mouse is placed on the second-level menu, and the first-level menu can be highlighted to indicate the location of the current menu. The jQuery plug-in is introduced to optimize simplicity and use less Code to achieve the desired function and share it with everyone.

Let’s take a look at the screenshots of the running effect:

The online demo address is as follows:

http://demo.jb51.net/js/2015/jquery-color-show-2level-css-menu-codes/

The specific code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>可高亮的二级CSS菜单</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(function(){
 $('.menu1 a').each(function(i){
  if($(this).attr('class')=='this'||$(this).attr('class')=='this hover'){
   $('.menu2').eq(i).show();
  }
  $(this).mousemove(function(){
   $('.menu1 a').removeClass('this');
   $(this).addClass('this');
   $('.menu2').hide();
   $('.menu2').eq(i).show();
   });
 });
});
</script>
<style type="text/css">
*{margin:0;padding:0;}
a{color:#000;text-decoration:none;}
.menu1{height:30px;background:#1B75C4;}
.menu1 a{display:inline;float:left;height:30px;line-height:30px;color:#fff;margin:0 5px;padding:0 5px;}
.menu1 a:hover,.menu1 a.this,.menu1 a.hover{background:#fff;color:#1B75C4;}
.menu2{height:30px;display:none;}
.menu2 a{display:inline;float:left;height:30px;line-height:30px;margin:0 5px;padding:0 5px;}
.menu2 a:hover{color:#1B75C4;}
</style>
</head>
<body>
<div class="menu">
 <div class="menu1">
  <a class="this" href="javascript:;">网站脚本</a>
  <a href="javascript:;">网页特效</a>
  <a href="javascript:;">大家喜欢的</a>
  <a href="javascript:;">不告诉你</a>
 </div>
 <div class="menu2">
  <a href="javascript:;">ASP</a>
  <a href="javascript:;">PHP</a>
  <a href="javascript:;">CGI</a>
 </div>
 <div class="menu2">
  <a href="javascript:;">菜单特效</a>
  <a href="javascript:;">CSS布局</a>
  <a href="javascript:;">表单特效</a>
  <a href="javascript:;">列表特效</a>
  <a href="javascript:;">浮动层</a>
 </div>
 <div class="menu2">
  <a href="javascript:;">美女</a>
  <a href="javascript:;">小姐</a>
  <a href="javascript:;">金钱</a>
  <a href="javascript:;">游戏</a>
 </div>
 <div class="menu2">
  <a href="javascript:;">秘密</a>
  <a href="javascript:;">年龄</a>
  <a href="javascript:;">其它</a>
 </div>
</div>
</body>
</html>

I hope this article will be helpful to everyone’s jquery programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn