我正在使用以下 JS 使我的 Bootstrap v3 导航在悬停时展开。
我这样做是为了让父链接成为一个链接。
<script type="text/javascript">
jQuery(function($) {
$('.navbar .dropdown').hover(function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(250).slideDown();
}, function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(100).slideUp();
});
$('.navbar .dropdown > a').click(function(){
location.href = this.href;
});
});
</script>
我在手机上遇到了一个问题,当你点击父链接时,你会在一瞬间看到子链接——但你会直接进入父链接……所以你没有能力选择父链接下方的子链接。
网站:http://crawfordtech.fastnetstaging.co.uk
有问题的父链接称为“解决方案”。
有什么想法可以做吗?
最佳答案
你可以把它包装在一个条件中,所以它会在你需要的时候运行 我只是从以前的元素中复制了 pasta'd,所以请忽略或随意使用其中的脚本。它还会产生下拉菜单。
<script type="text/javascript">
//boostrap hover script
jQuery(document).ready(function($){
if ($(document).width() > 800){
(function(e,d,b){var a=0;var f=null;var c={x:0,y:0};e("[data-toggle]").closest("li").on("mouseenter",function(g){if(f){f.removeClass("open")}d.clearTimeout(a);f=e(this);a=d.setTimeout(function(){f.addClass("open")},b)}).on("mousemove",function(g){if(Math.abs(c.x-g.ScreenX)>4||Math.abs(c.y-g.ScreenY)>4){c.x=g.ScreenX;c.y=g.ScreenY;return}if(f.hasClass("open")){return}d.clearTimeout(a);a=d.setTimeout(function(){f.addClass("open")},b)}).on("mouseleave",function(g){d.clearTimeout(a);f=e(this);a=d.setTimeout(function(){f.removeClass("open")},b)})})(jQuery,window,200);
}});
</script>
关于javascript - Bootstrap 移动下拉父链接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21454672/