jquery实现可横向和竖向展开的动态下滑菜单效果
网络编程 2021-07-04 21:48www.168986.cn编程入门
这篇文章主要介绍了jquery实现可横向和竖向展开的动态下滑菜单效果,以实例形式较为详细的分析了jquery实现横向与竖向展开菜单的相关技巧,非常具有实用价值,需要的朋友可以参考下
本文实例讲述了jquery实现可横向和竖向展开的动态下滑菜单效果。分享给大家供大家参考。具体如下
这里演示了两个下拉导航菜单的效果,用jquery.easing.1.3.js和jquery.naviDropDown.1.0.js以及jquery.hoverIntent.minified.js共同实现,最新的jquery版本也可以引入,在演示页面中,分别有横向水平向下滑出的下拉菜单,还有纵向垂直布局向右滑出的导航菜单,根据你的需要选择使用。
运行效果截图如下
在线演示地址如下
具体代码如下
<!DOCTYPE html> <head> <title>jQuery纵向横向动态下拉导航菜单</title> <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script> <script type="text/javascript" src="js/jquery.easing.1.3.js"></script> <script type="text/javascript" src="js/jquery.hoverIntent.minified.js"></script> <script type="text/javascript"> //jquery.naviDropDown.1.0.js (function($){ $.fn.naviDropDown = function(options) { var defaults = { dropDownClass: 'dropdown', dropDownWidth: 'auto', slideDownEasing: 'easeInOutCirc', slideUpEasing: 'easeInOutCirc', slideDownDuration: 500, slideUpDuration: 500, orientation: 'horizontal' }; var opts = $.extend({}, defaults, options); return this.each(function() { var $this = $(this); $this.find('.'+opts.dropDownClass).css('width', opts.dropDownWidth).css('display', 'none'); var buttonWidth = $this.find('.'+opts.dropDownClass).parent().width() + 'px'; var buttonHeight = $this.find('.'+opts.dropDownClass).parent().height() + 'px'; if(opts.orientation == 'horizontal') { $this.find('.'+opts.dropDownClass).css('left', '0px').css('', buttonHeight); } if(opts.orientation == 'vertical') { $this.find('.'+opts.dropDownClass).css('left', buttonWidth).css('', '0px'); } $this.find('li').hoverIntent(getDropDown, hideDropDown); }); function getDropDown(){ activeNav = $(this); showDropDown(); } function showDropDown(){ activeNav.find('.'+opts.dropDownClass).slideDown({duration:opts.slideDownDuration, easing:opts.slideDownEasing}); } function hideDropDown(){ activeNav.find('.'+opts.dropDownClass).slideUp({duration:opts.slideUpDuration, easing:opts.slideUpEasing});//hides the current dropdown } }; })(jQuery); </script> <script type="text/javascript"> $(function(){ $('#navigation_horiz').naviDropDown({ dropDownWidth: '300px' }); $('#navigation_vert').naviDropDown({ dropDownWidth: '300px', orientation: 'vertical' }); }); </script> <style type="text/css"> {margin:0; padding:0; font-family:Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; line-height:16px} .container {margin:10px auto; width:950px; height:300px; background:#eee; padding:50px 0 0 0} #navigation_horiz {width:820px; clear:both; padding:0 0 0 0; margin:0 auto} #navigation_horiz ul {height:50px; display:block} #navigation_horiz ul li {display:block; float:left; width:200px; height:50px; background:#999; margin:0 1px 0 0; position:relative} #navigation_horiz ul li a.navlink {display:block; width:200px; height:30px; padding: 20px 0 0 0; text-align:center; color:#fff; text-decoration:none} #navigation_horiz .dropdown {position:absolute; padding:20px; border-bottom-right-radius:10px; border-bottom-left-radius:10px; -moz-border-radius-bottomright:10px; -moz-border-radius-bottomleft:10px} #navigation_vert {width:820px; clear:both; padding:0 0 0 0; margin:0 auto} #navigation_vert ul {height:50px; display:block} #navigation_vert ul li {display:block; width:200px; height:50px; background:#999; margin:0 0 1px 0; position:relative} #navigation_vert ul li a.navlink {display:block; display:inline-block; width:200px; height:30px; padding: 20px 0 0 0; text-align:center; color:#fff; text-decoration:none} #navigation_vert .dropdown {position:absolute; padding:20px; border-bottom-right-radius:10px; border--right-radius:10px; -moz-border-radius-bottomright:10px; -moz-border-radius-right:10px} #navigation_horiz ul li #dropdown_one {background:#c; color:#fff} #navigation_horiz ul li #dropdown_one a {color:red} #navigation_horiz ul li #dropdown_two {background:#c; color:#fff} #navigation_horiz ul li #dropdown_two a {color:black} #navigation_horiz ul li #dropdown_three {background:#c; color:#fff} #navigation_horiz ul li #dropdown_three a {color:gray} #navigation_vert ul li #dropdown_four {background:#333; color:#fff} #navigation_vert ul li #dropdown_four a {color:red} #navigation_vert ul li #dropdown_five {background:#666; color:#fff} #navigation_vert ul li #dropdown_five a {color:black} #navigation_vert ul li #dropdown_six {background:#777; color:#fff} #navigation_vert ul li #dropdown_six a {color:orange} </style> </head> <body> <div class="container"> <div id="navigation_horiz"> <ul> <li> <a href="" class="navlink">List Item</a> <div class="dropdown" id="dropdown_one"> <p><a href="#">This is a Link</a></p> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin blandit sodales justo, id fringilla eros dapibus vitae. Morbi molestie enim diam, a vulputate neque. Morbi sit amet nunc id quam mollis aliquet. Donec sed massa justo, ut congue enim. Praesent lobortis viverra dolor modo euismod. </p> </div><!-- .dropdown_menu --> </li> <li> <a href="" class="navlink">List Item</a> <div class="dropdown" id="dropdown_two"> <p><a href="#">This is a Link</a></p> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin blandit sodales justo, id fringilla eros dapibus vitae. Morbi molestie enim diam, a vulputate neque. Morbi sit amet nunc id quam mollis aliquet. Donec sed massa justo, ut congue enim. Praesent lobortis viverra dolor modo euismod. </p> </div><!-- .dropdown_menu --> </li> <li><a href="" class="navlink">List Item</a></li> <li> <a href="" class="navlink">List Item</a> <div class="dropdown" id="dropdown_three"> <p><a href="#">This is a Link</a></p> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin blandit sodales justo, id fringilla eros dapibus vitae. Morbi molestie enim diam, a vulputate neque. Morbi sit amet nunc id quam mollis aliquet. Donec sed massa justo, ut congue enim. Praesent lobortis viverra dolor modo euismod. </p> </div><!-- .dropdown_menu --> </li> </ul> </div><!-- #navigation_horiz --> </div><!-- .container --> <div class="container"> <div id="navigation_vert"> <ul> <li> <a href="" class="navlink">List Item</a> <div class="dropdown" id="dropdown_four"> <p><a href="#">This is a Link</a></p> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin blandit sodales justo, id fringilla eros dapibus vitae. Morbi molestie enim diam, a vulputate neque. Morbi sit amet nunc id quam mollis aliquet. Donec sed massa justo, ut congue enim. Praesent lobortis viverra dolor modo euismod. </p> </div><!-- .dropdown_menu --> </li> <li> <a href="" class="navlink">List Item</a> <div class="dropdown" id="dropdown_five"> <p><a href="#">This is a Link</a></p> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin blandit sodales justo, id fringilla eros dapibus vitae. Morbi molestie enim diam, a vulputate neque. Morbi sit amet nunc id quam mollis aliquet. Donec sed massa justo, ut congue enim. Praesent lobortis viverra dolor modo euismod. </p> </div><!-- .dropdown_menu --> </li> <li><a href="" class="navlink">List Item</a></li> <li> <a href="" class="navlink">List Item</a> <div class="dropdown" id="dropdown_six"> <p><a href="#">This is a Link</a></p> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin blandit sodales justo, id fringilla eros dapibus vitae. Morbi molestie enim diam, a vulputate neque. Morbi sit amet nunc id quam mollis aliquet. Donec sed massa justo, ut congue enim. Praesent lobortis viverra dolor modo euismod. </p> </div><!-- .dropdown_menu --> </li> </ul> </div><!-- #navigation_vert --> </div><!-- .container --> </body> </html>
希望本文所述对大家的jquery程序设计有所帮助。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程