把bootstrap4dropdown的导航下拉菜单触发方式改为鼠标浮动触发

把bootstrap4dropdown的导航下拉菜单触发方式改为鼠标浮动触发

2023年7月9日发(作者:)

把bootstrap4dropdown的导航下拉菜单触发⽅式改为⿏标浮动触发⽅法1:很简单,css中加⼊如下代码.dropdown:hover>.dropdown-menu { display: block;}.dropdown>.dropdown-toggle:active { pointer-events: none;}修改完成后发现⼀个⼩问题,菜单和⽂字间有⼀点空隙,⿏标移动到空隙后菜单就隐藏了。我们再修改 dropdown-menu 的样式,加⼀个 mt-0 的样式就没有空隙了。

另⽅法2:这个是bootstrap3的⽅法,修改后; (function ($, window, undefined) {// outside the scope of the jQuery plugin to// keep track of all dropdownsvar $allDropdowns = $();// if instantlyCloseOthers is true, then it will instantly// shut other nav items when a new one is hovered over$.wnHover = function (options) {// the element we really care about// is the dropdown-toggle's parent$allDropdowns = $(());return (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;$(function () {if (tlyCloseOthers === true) {$Class('show');$(".dropdown-menu").removeClass('show');}imeout(timeout);$(this).addClass('show');$(this).find(".dropdown-menu").addClass('show');}, function () {timeout = eout(function () {$Class('show');$(".dropdown-menu").removeClass('show');}, );});});};$('[data-hover="dropdown"]').dropdownHover();})(jQuery, this);

//在你调⽤的地⽅⾥加上 time是你给的反应时间。⽐如500这样。$('.dropdown-toggle').dropdownHover(time);//点击链接如下:$('wn-toggle').one('click', function () {if ($(this).attr('href')!="") = $(this).attr('href');});

发布者:admin,转转请注明出处:http://www.yc00.com/web/1688853081a176664.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信