Home  >  Article  >  Web Front-end  >  JQuery implements mouse scrolling to display navigation drop-down list_jquery

JQuery implements mouse scrolling to display navigation drop-down list_jquery

WBOY
WBOYOriginal
2016-05-16 17:22:521042browse

When there are many items in the website navigation bar, we often hide the columns in the same level directory first. Displayed when the user's mouse rolls over. This is a navigation bar drop-down list implemented in javascript. The editor will explain it to you step by step. It is worth noting that we use Jquery, a framework of Javascript, to implement this. Therefore, you must download Jquery when using it.

Create the HTML code first

Copy the code The code is as follows:

< html>


Jquery test web page</ title> <br><link rel="stylesheet" href="./css/layout.css" type="text/css" /> <br><script src="./js/jquery.js " type="text/javascript"></script> <br><script src="./js/basic.js" type="text/javascript"></script> <br>< ;/head> <br><body> <br><p id="it">IT industry</p> <br><ul id="ul"> <br><li> ;Baidu</li> <br><li>Google</li> <br><li>NetEase</li> <br><li>Tencent</li> <br>< ;li>Taobao</li> <br></ul> <br></body> <br></html> <br> </div> <br>This code contains the Jquery library: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="3958" class="copybut" id="copybut3958" onclick="doCopy('code3958')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code3958"> <br><script src="./js/jquery. js" type="text/javascript"></script> <br> </div> <br>Here we put the CSS and JS files separately in an external file. The code of <br>layout.css file is: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="81932" class="copybut" id="copybut81932" onclick="doCopy('code81932')"><u>Copy the code</u></a></span> The code is as follows:</div> <div class="codebody" id="code81932"> <br>@ CHARSET "GBK"; <br>body{ <br>font:12px Arial,Verdana; <br>} <br>ul{ <br>margin:0px; <br>padding:0px; <br>list-style- type:none; <br>} <br>#it{ <br>margin:0px; <br>width:80px; <br>height:25px; <br>color:white; <br>text-align:center ; <br>line-height:25px; <br>cursor:pointer; <br>background:black; <br>border:1px solid white; <br>} <br>#ul li{ <br>width:80px ; <br>height:25px; <br>color:white; <br>text-align:center; <br>line-height:25px; <br>cursor:pointer; <br>background:black; <br> border:1px solid white; <br>} <br>.highLight{ <br>width:80px; <br>height:25px; <br>background:white; <br>border:1px solid blue; <br>color :black; <br>} <br> </div> <br>You can design the CSS code according to your favorite style. It is important to explain the JS file here. <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="21453" class="copybut" id="copybut21453" onclick="doCopy('code21453')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code21453"> <br>$(document).ready(function (){ <br>$('#ul').hide(); //Open the page to hide the drop-down list<br>$('#it').hover( //When the mouse slides over the navigation column<br>function(){ <br>$('#ul').show(); //Show drop-down list<br>$(this).css({'color':'red','background-color':'orange'}); //Set the navigation column style, eye-catching <br>}, <br>function(){ <br>$('#ul').hide(); //Hide the drop-down list after the mouse is moved away <br>} <br>); <br>$('#ul').hover( //The drop-down list itself should also be displayed when the mouse slides over it to prevent the drop-down list from being clickable <br>function(){ <br>$('#ul') .show(); <br>}, <br>function(){ <br>$('#ul').hide(); <br>$('#it').css({'color': 'white','background-color':'black'}); //After the mouse moves away from the drop-down list, the style of the navigation bar is also cleared <br>} <br>); <br>$('li'). hover( //Mouse over the drop-down list to change the current column style <br>function(){ <br>$(this).css({'color':'red','background-color':'orange'} ); <br>}, <br>function(){ <br>$(this).css({'color':'white','background-color':'black'}); <br>} <br>); <br>}); <br> </div> <br>Due to the current problem of the website editor, it is not possible to upload pictures. If you don’t have pictures, you can test it locally first to see the effect.</div><div class="nphpQianMsg"><div class="clear"></div></div><div class="nphpQianSheng"><span>Statement:</span><div>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</div></div></div><div class="nphpSytBox"><span>Previous article:<a class="dBlack" title="Using javascript to determine the IE version number is simple, practical and backward compatible_javascript skills" href="http://m.php.cn/faq/16172.html">Using javascript to determine the IE version number is simple, practical and backward compatible_javascript skills</a></span><span>Next article:<a class="dBlack" title="Using javascript to determine the IE version number is simple, practical and backward compatible_javascript skills" href="http://m.php.cn/faq/16174.html">Using javascript to determine the IE version number is simple, practical and backward compatible_javascript skills</a></span></div><div class="nphpSytBox2"><div class="nphpZbktTitle"><h2>Related articles</h2><em><a href="http://m.php.cn/article.html" class="bBlack"><i>See more</i><b></b></a></em><div class="clear"></div></div><ins class="adsbygoogle" style="display:block" data-ad-format="fluid" data-ad-layout-key="-6t+ed+2i-1n-4w" data-ad-client="ca-pub-5902227090019525" data-ad-slot="8966999616"></ins><script> (adsbygoogle = window.adsbygoogle || []).push({}); </script><ul class="nphpXgwzList"><li><b></b><a href="http://m.php.cn/faq/1609.html" title="An in-depth analysis of the Bootstrap list group component" class="aBlack">An in-depth analysis of the Bootstrap list group component</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/faq/1640.html" title="Detailed explanation of JavaScript function currying" class="aBlack">Detailed explanation of JavaScript function currying</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/faq/1949.html" title="Complete example of JS password generation and strength detection (with demo source code download)" class="aBlack">Complete example of JS password generation and strength detection (with demo source code download)</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/faq/2248.html" title="Angularjs integrates WeChat UI (weui)" class="aBlack">Angularjs integrates WeChat UI (weui)</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/faq/2351.html" title="How to quickly switch between Traditional Chinese and Simplified Chinese with JavaScript and the trick for websites to support switching between Simplified and Traditional Chinese_javascript skills" class="aBlack">How to quickly switch between Traditional Chinese and Simplified Chinese with JavaScript and the trick for websites to support switching between Simplified and Traditional Chinese_javascript skills</a><div class="clear"></div></li></ul></div></div><ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5902227090019525" data-ad-slot="5027754603"></ins><script> (adsbygoogle = window.adsbygoogle || []).push({}); </script><footer><div class="footer"><div class="footertop"><img src="/static/imghwm/logo.png" alt=""><p>Public welfare online PHP training,Help PHP learners grow quickly!</p></div><div class="footermid"><a href="http://m.php.cn/about/us.html">About us</a><a href="http://m.php.cn/about/disclaimer.html">Disclaimer</a><a href="http://m.php.cn/update/article_0_1.html">Sitemap</a></div><div class="footerbottom"><p> © php.cn All rights reserved </p></div></div></footer><script>isLogin = 0;</script><script type="text/javascript" src="/static/layui/layui.js"></script><script type="text/javascript" src="/static/js/global.js?4.9.47"></script></div><script src="https://vdse.bdstatic.com//search-video.v1.min.js"></script><link rel='stylesheet' id='_main-css' href='/static/css/viewer.min.css' type='text/css' media='all'/><script type='text/javascript' src='/static/js/viewer.min.js?1'></script><script type='text/javascript' src='/static/js/jquery-viewer.min.js'></script><script>jQuery.fn.wait = function (func, times, interval) { var _times = times || -1, //100次 _interval = interval || 20, //20毫秒每次 _self = this, _selector = this.selector, //选择器 _iIntervalID; //定时器id if( this.length ){ //如果已经获取到了,就直接执行函数 func && func.call(this); } else { _iIntervalID = setInterval(function() { if(!_times) { //是0就退出 clearInterval(_iIntervalID); } _times <= 0 || _times--; //如果是正数就 -- _self = $(_selector); //再次选择 if( _self.length ) { //判断是否取到 func && func.call(_self); clearInterval(_iIntervalID); } }, _interval); } return this; } $("table.syntaxhighlighter").wait(function() { $('table.syntaxhighlighter').append("<p class='cnblogs_code_footer'><span class='cnblogs_code_footer_icon'></span></p>"); }); $(document).on("click", ".cnblogs_code_footer",function(){ $(this).parents('table.syntaxhighlighter').css('display','inline-table');$(this).hide(); }); $('.nphpQianCont').viewer({navbar:true,title:false,toolbar:false,movable:false,viewed:function(){$('img').click(function(){$('.viewer-close').trigger('click');});}}); </script></body></html>