亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Bootstrap中的Dropdown下拉菜單更改為懸停(hover)觸發(fā)

 更新時(shí)間:2016年08月31日 09:09:53   投稿:mrr  
在使用bootstrap制作響應(yīng)式導(dǎo)航條時(shí),dropdown組件用的比較多,dropdown默認(rèn)鼠標(biāo)左鍵單擊才展開,如果使用鼠標(biāo)放上去(hover)就展開則會(huì)省去點(diǎn)擊時(shí)間,這樣能提高效率,下面小編給大家解答下實(shí)現(xiàn)思路

在使用bootstrap制作后臺(tái)時(shí)用到了響應(yīng)式導(dǎo)航條,其中dropdown組件更是用的比較多,用的多需要點(diǎn)擊的就多,dropdown默認(rèn)鼠標(biāo)左鍵單擊才展開,如果使用鼠標(biāo)放上去(hover)就展開則會(huì)省去點(diǎn)擊時(shí)間,這樣能提高效率。

原本的改造思路是:給dropdown元素綁定hover事件,hover上去的時(shí)候,執(zhí)行該元素的click事件——即把hover同步為click,hover即為click。

但想到與其自己來改造,不如先在網(wǎng)上搜索搜索看看有沒有現(xiàn)成的插件,果不其然就搜索到了,托管在github上的代碼網(wǎng)址:查看

在這兒就直接把代碼復(fù)制出來:

;(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);

可以看到作者在插件前面加了個(gè)分號(hào);,增加了插件的兼容性,因?yàn)榭赡苌弦粋€(gè)js代碼沒寫;,如果在此不加分號(hào)則可能因?yàn)闆]換行導(dǎo)致js出錯(cuò)。

插件支持HTML元素data-*傳參,也支持初始化傳參。將此js代碼放在bootstrap原本的js代碼后面執(zhí)行即可。

以上所述是小編給大家介紹的Bootstrap中的Dropdown下拉菜單更改為懸停(hover)觸發(fā),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論