bootstrap的dropdown 改为hover触发

参考 https://github.com/ibmsoft/twitter-bootstrap-hover-dropdown

现在bootstrap 的js中添加

 1 // bootstrap响应式导航条<br>;(function($, window, undefined) {
 2  // outside the scope of the jQuery plugin to
 3  // keep track of all dropdowns
 4  var $allDropdowns = $();
 5  
 6  // if instantlyCloseOthers is true, then it will instantly
 7  // shut other nav items when a new one is hovered over
 8  $.fn.dropdownHover = function(options) {
 9  
10   // the element we really care about
11   // is the dropdown-toggle's parent
12   $allDropdowns = $allDropdowns.add(this.parent());
13  
14   return this.each(function() {
15    var $this = $(this).parent(),
16     defaults = {
17      delay: 500,
18      instantlyCloseOthers: true
19     },
20     data = {
21      delay: $(this).data('delay'),
22      instantlyCloseOthers: $(this).data('close-others')
23     },
24     options = $.extend(true, {}, defaults, options, data),
25     timeout;
26  
27    $this.hover(function() {
28     if(options.instantlyCloseOthers === true)
29      $allDropdowns.removeClass('open');
30  
31     window.clearTimeout(timeout);
32     $(this).addClass('open');
33    }, function() {
34     timeout = window.setTimeout(function() {
35      $this.removeClass('open');
36     }, options.delay);
37    });
38   });
39  };
40  
41  $('[data-hover="dropdown"]').dropdownHover();
42 })(jQuery, this);

后,

<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown"></a>

恩 马克

转载于:https://www.cnblogs.com/woaichirourou/p/7504170.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值