bootstrap的导航改造
在使用bootstrap
制作后台时用到了响应式导航条,其中dropdown
组件更是用的比较多,用的多需要点击的就多,dropdown
默认鼠标左键单击才展开,如果使用鼠标放上去(hover
)就展开则会省去点击时间,这样能提高效率。
原本的改造思路是:给dropdown
元素绑定hover
事件,hover
上去的时候,执行该元素的click
事件——即把hover
同步为click
,hover
即为click
。
但想到与其自己来改造,不如先在网上搜索搜索看看有没有现成的插件,果不其然就搜索到了,托管在github
上的代码网址:查看
在这儿就直接把代码复制出来:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
/* * Project: Twitter Bootstrap Hover Dropdown * Author: Cameron Spear * Contributors: Mattia Larentis * * Dependencies?: Twitter Bootstrap's Dropdown plugin * * A simple plugin to enable twitter bootstrap dropdowns to active on hover and provide a nice user experience. * * No license, do what you want. I'd love credit or a shoutout, though. * */ ;( function ($, window, undefined) { // outside the scope of the jQuery plugin to // keep track of all dropdowns var $allDropdowns = $(); // if instantlyCloseOthers is true, then it will instantly // shut other nav items when a new one is hovered over $.fn.dropdownHover = function (options) { // the element we really care about // is the dropdown-toggle's parent $allDropdowns = $allDropdowns.add( this .parent()); return this .each( function () { var $ this = $( this ).parent(), defaults = { delay: 500, instantlyCloseOthers: true }, data = { delay: $( this ).data('delay '), instantlyCloseOthers: $(this).data(' close-others ') }, options = $.extend(true, {}, defaults, options, data), timeout; $this.hover(function() { if(options.instantlyCloseOthers === true) $allDropdowns.removeClass(' open '); window.clearTimeout(timeout); $(this).addClass(' open '); }, function() { timeout = window.setTimeout(function() { $this.removeClass(' open '); }, options.delay); }); }); }; $(' [data-hover= "dropdown" ]').dropdownHover(); })(jQuery, this ); |
可以看到作者在插件前面加了个分号;
,增加了插件的兼容性,因为可能上一个js
代码没写;
,如果在此不加分号则可能因为没换行导致js
出错。
插件支持HTML
元素data-*
传参,也支持初始化传参。将此js
代码放在bootstrap
原本的js
代码后面执行即可。
bootstrap的导航改造的更多相关文章
- [置顶]
bootstrap自定义样式-bootstrap侧边导航栏的实现
前言 bootstrap自带的响应式导航栏是向下滑动的,有时满足不了个性化的需求,需要做一个类似于android drawerLayout 侧滑的菜单,这就是我要实现的bootstrap自定义侧滑菜单 ...
- 第二百四十九节,Bootstrap附加导航插件
第二百四十九节,Bootstrap附加导航插件 学习要点: 1.附加导航插件 本节课我们主要学习一下 Bootstrap 中的附加导航插件 一.附加导航 注意:此插件要使用 bootstrap3.0. ...
- Bootstrap 附加导航(Affix)插件
bootstrap 附加导航(Affix)插件允许某个div元素固定到页面中的某个位置.您可以打开或关闭使用该插件之间进行切换 后续再写
- bootstrap框架 导航条组件使用
本文记载boot 导航条组件使用方法 导航条组件 导航条是在您的应用或网站中作为导航页头的响应式基础组件.它们在移动设备上可以折叠(并且可开可关),且在视口(viewport)宽度增加时逐渐变为水平展 ...
- Bootstrap~多级导航(级联导航)的实现
回到目录 在bootstrap官方来说,导航最多就是两级,两级以上是无法实现的,大叔找了一些第三方的资料,终于找到一个不错的插件,使用上和效果上都还不错,现在和大家分享一下 插件地址:http://v ...
- bootstrap完整导航栏
效果图: 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- ⑩bootstrap组件 导航 使用基础案例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...
- bootstrap顶部导航遮挡下面内容的解决办法
使用bootstrap设置顶部导航,并将导航栏固定,代码如下: <nav class="navbar navbar-expand-lg navbar-light bg-light fi ...
- Bootstrap 固定导航条
默认情况下,导航条的定位属性为 static,它的位置由它的HTML代码中定义的顺序出现,并随着页面向下滚动而消失.也可以改变它的定位方式,让它固定显示在浏览器窗口的顶部或底部. 1.固定在顶部 如果 ...
随机推荐
- spark aggregate
该函数官方的api,说的不是很明白: aggregate(zeroValue, seqOp, combOp) Aggregate the elements of each partition, and ...
- leetcode 326. Power of Three(不用循环或递归)
leetcode 326. Power of Three(不用循环或递归) Given an integer, write a function to determine if it is a pow ...
- Windows Server 2012 R2超级虚拟化之七 远程桌面服务的增强
Windows Server 2012 R2超级虚拟化之七 远程桌面服务的增强 在Windows Server 2012提供的远程桌面服务角色,使用户能够连接到虚拟桌面. RemoteApp程序.基 ...
- 聚类算法初探(六)OPTICS
最近由于工作需要,对聚类算法做了一些相关的调研.现将搜集到的资料和自己对算法的一些理解整理如下,供大家参考. 另外在算法代码方面,我也做了一些实现(包括串行和并行),欢迎感兴趣的朋友探讨和交流. 第一 ...
- Java反射及依赖注入简单模拟
一.编写Dao类 ? 1 2 3 4 5 6 7 8 9 10 11 package cn.com.songjy.annotation; import java.util.Date; publ ...
- mvn profile 深层次目录打参数核心配置
<build> <resources> <resource> <directory>src/main/resources</directory&g ...
- C#读取csv格式文件
方法1:用一个System.Web.UI.HtmlControls.HtmlInputFile去handle文件选取 以下是button click event中的code,用来执行当文件选取了之后读 ...
- Gson解析JsonObject和JsonArray
Gson中重要的几个核心类: Gson.JsonParser.JsonObject.JsonArray. 下面就是解析的步骤: public void parserJsonArray(String s ...
- php变量的引用及函数的引用
Php变量的引用及函数的引用放回 变量的引用 $a="ABC"; $b =&$a; echo $a;//这里输出:ABC echo $b;//这里输 ...
- php中如何获取文件的正确路径
以上面的图片为例子 //我们这里需要使用到 $_FILE echo "<pre>"; print_r($_FILES); echo $_SERVER['DOCUMENT ...