简体   繁体   English

具有jQuery悬停菜单选项卡放置的Bootstrap固定顶部导航栏

[英]Bootstrap fixed-top navbar with jquery hover menu tab drops

I'm learning how to use bootstrap framework on building the website. 我正在学习如何在构建网站时使用引导框架。 And there is a navbar hover effect I'd like to replicate. 我想复制一个导航栏悬停效果。 Please see the example below that provided by bootstrap. 请参阅下面的引导程序提供的示例。 https://www.aceandtate.com/ The effect is: The menu texts always show while the nav bar only drops when your mouse over the nav-bar container area. https://www.aceandtate.com/效果是:菜单文本始终显示,而导航栏只有在鼠标悬停在导航栏容器区域上时才会放下。 Navbar white unfold drops while mouse hover 鼠标悬停时导航栏白色展开掉落

Can anyone show me how to do that? 谁能告诉我该怎么做?

Thanks, 谢谢,

First, create your dropdown with bootstrap. 首先,使用引导程序创建下拉列表。 (I assume you have index.html,css folder, and js folder in one folder). (我假设您在一个文件夹中有index.html,css文件夹和js文件夹)。 index.html where you use bootstrap to create dropdown menu. 使用引导程序创建下拉菜单的index.html。

屏幕截图

in your js folder, edit (create if none) your script.js file. 在您的js文件夹中,编辑(如果没有则创建)您的script.js文件。 Add this script 添加此脚本

$('ul.nav li.dropdown').hover(function() {
    $(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn(500);
}, function() {
    $(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut(500);
});

After that, include that script (if not yet include in your html file) 之后,添加该脚本(如果尚未包含在html文件中)

<script src="js/scripts.js"></script>

I place it before 我把它放在前面

</body>

Now your dropdown menu will automatic show when you hover the mouse 现在,将鼠标悬停在您的下拉菜单上会自动显示

徘徊

Source : http://codepen.io/betdream/pen/frDqh 来源: http : //codepen.io/betdream/pen/frDqh

Try this for on menu dropdown hover: 在菜单下拉悬停上尝试以下操作:

Add this JS: 添加此JS:

$('ul.nav li.dropdown').hover(function() {
      $(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn(500);
    }, function() {
      $(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut(500);
    });

If you want to show menu always open in mobile device then add media query in your CSS file and set property display:block 如果要显示菜单始终在移动设备中打开,则在CSS文件中添加媒体查询并设置属性display:block

For media query check this for your reference MEDIA QUERIES FOR COMMON DEVICE 对于媒体查询,请检查此内容以供参考常见设备的媒体查询

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 jquery &amp; bootstrap 5 中的主要固定顶部导航栏下的特定部分的滚动上添加第二个粘性导航栏? - How to add a second sticky navbar on scroll of a particular section, under the primary fixed-top navbar, in jquery & bootstrap 5? 如何在活动项目上实现带有背景图像和向下箭头的这种bootstrap固定顶部导航栏菜单 - How to realize such a bootstrap fixed-top navbar menu with background image and arrow down on active item Navbar和THead Fixed-Top - Navbar and THead Fixed-Top Bootstrap 4-如何使固定式导航栏在滚动时消失 - Bootstrap 4 - How to make fixed-top navbar disappear on scroll 如何在带有左右缩进的Bootstrap上实现固定顶部菜单? - How to realize fixed-top menu on Bootstrap with left and right indentation? 如何使固定顶部的引导程序菜单背景仅向右或向左粘? - How to make fixed-top bootstrap menu background sticky only to right or left? 如何在固定顶部导航栏和固定底部(带引导程序)之间切换时如何启用CSS转换 - How can I enable CSS Transitions when switching between a fixed-top navbar and a fixed-bottom (w/ Bootstrap) 使用jQuery Bootstrap#navbar-fixed-top - Bootstrap #navbar-fixed-top using jquery Bootstrap Navbar固定在顶部 - Bootstrap Navbar Fixed to Top jQuery滚动到Bootstrap导航栏固定在标题顶部的顶部空间 - JQuery scroll to title top space with Bootstrap navbar fixed top
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM