JQuery navigation menu selection effects_jquery
1. Realizing the effect
1. Initialization effect: no styles and special effects added
2. Add CSS style
3. Final effect
2. JQuery code
<!--编写JQuery代码--> <script type="text/javascript"> $(document).ready(function(){ $(".level>a").click(function(){ $(this).addClass("current") //给当前元素添加current样式 .next().show() //下一个元素显示 .parent().siblings().children("a").removeClass("current") //父元素的同辈元素的子元素<a>移除“current”样式 .next().hide(); //他们的下一个元素隐藏 return false; }) }) </script>
3. Complete code
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-"> <title>JQuery制作导航栏</title> <script type="text/javascript" src="../JQuery库文件/jquery-...min.js"></script> <!--引入JQuery库文件--> <style type="text/css"> /*设置通用样式*/ *{ padding: ; margin: ; } .box{ margin: auto; border: solid #BEBEBE px; width: px; } ul{ list-style: none; } a { color:#F; text-decoration:none; line-height: px; } /*level*/ .level a{ display: block; /*!!!转换为块状元素*/ height: px; width: px; background-color: #EBFF; padding-left: px; border: solid px #BEBEBE; } .level a.current{ background-color:#BDEF; } /*level*/ .level a{ background: #ffffff; color: #EEE; border: none; } .level a:hover { color:red; } .level{ display: none; } </style> <!--编写JQuery代码--> <script type="text/javascript"> $(document).ready(function(){ $(".level>a").click(function(){ $(this).addClass("current") //给当前元素添加current样式 .next().show() //下一个元素显示 .parent().siblings().children("a").removeClass("current") //父元素的同辈元素的子元素<a>移除“current”样式 .next().hide(); //他们的下一个元素隐藏 return false; }) }) </script> </head> <body> <div class="box"> <ul class="menu"> <li class="level"> <a href="#">衬衫</a> <ul class="level"> <li><a href="#">短袖衬衫</a></li> <li><a href="#">长袖衬衫</a></li> <li><a href="#">短袖T恤</a></li> <li><a href="#">长袖T恤</a></li> </ul> </li> <li class="level"> <a href="#">卫衣</a> <ul class="level"> <li><a href="#">开襟卫衣</a></li> <li><a href="#">套头卫衣</a></li> <li><a href="#">运动卫衣</a></li> <li><a href="#">童装卫衣</a></li> </ul> </li> <li class="level"> <a href="#">裤子</a> <ul class="level"> <li><a href="#">短裤</a></li> <li><a href="#">休闲裤</a></li> <li><a href="#">牛仔裤</a></li> <li><a href="#">免烫卡其裤</a></li> </ul> </li> </ul> </div> </body> </html>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...
