bootstrap dropdown的点击变为:hover 后自动下拉


翻了不少地方。找到这段代码。

先把这个复制到bootstrap.min.js下面增加

 1 /*
 2 
 3  * Project: Twitter Bootstrap Hover Dropdown
 4  * Author: Cameron Spear
 5  * Contributors: Mattia Larentis
 6  *
 7  * Dependencies?: Twitter Bootstrap's Dropdown plugin
 8  *
 9  * A simple plugin to enable twitter bootstrap dropdowns to active on hover and provide a nice user experience.
10  *
11  * No license, do what you want. I'd love credit or a shoutout, though.
12  *
13  * http://cameronspear.com/blog/twitter-bootstrap-dropdown-on-hover-plugin/
14  */
15 ;(function($, window, undefined) {
16     // outside the scope of the jQuery plugin to
17     // keep track of all dropdowns
18     var $allDropdowns = $();
19          
20     // if instantlyCloseOthers is true, then it will instantly
21     // shut other nav items when a new one is hovered over
22     $.fn.dropdownHover = function(options) {
23          
24         // the element we really care about
25         // is the dropdown-toggle's parent
26         $allDropdowns = $allDropdowns.add(this.parent());
27          
28         return this.each(function() {
29             var $this = $(this).parent(),
30                 defaults = {
31                     delay: 500,
32                     instantlyCloseOthers: true
33                 },
34                 data = {
35                     delay: $(this).data('delay'),
36                     instantlyCloseOthers: $(this).data('close-others')
37                 },
38                 options = $.extend(true, {}, defaults, options, data),
39                 timeout;
40          
41             $this.hover(function() {
42                 if(options.instantlyCloseOthers === true)
43                     $allDropdowns.removeClass('open');
44          
45                 window.clearTimeout(timeout);
46                 $(this).addClass('open');
47             }, function() {
48                 timeout = window.setTimeout(function() {
49                     $this.removeClass('open');
50                 }, options.delay);
51             });
52         });
53     };
54          
55     $('[data-hover="dropdown"]').dropdownHover();
56 })(jQuery, this);

在你调用的地方里加上
$('.dropdown-toggle').dropdownHover(time);

//time是你给的反应时间。比如500这样。

然后加点击链接如下:
$('a.dropdown-toggle').one('click',function(){

location.href= $(this).attr('href');

});

优质内容筛选与推荐>>
1、Apue.2e Chapter8 Process Control
2、Directory Listing Dendied
3、thinkqueue 后台运行常驻程序
4、记一个神奇的Bug
5、[导入]How Do I: Use the ASP.NET AJAX MaskedEdit Controls?


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号