Answer the question
In order to leave comments, you need to log in
How to fix hover issue in bootstrap menu?
There is a bootstrap menu
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Главная</a><span>|</span></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle active" data-toggle="dropdown">Наши услуги</a><span>|</span>
<ul class="dropdown-menu dropdown-menu-left">
<li class="li-sub-dropdown">
<div class="trian"></div>
<a href="#">Создание адаптивных сайтов <span>>></span></a>
<ul class="sub-dropdown-menu">
<li><a href="#">Пункт1</a></li>
<li><a href="#">Пункт2</a></li>
</ul>
</li>
<li><a href="#">Подпункт1</a></li>
<li><a href="#">Подпункт2</a></li>
</ul>
</li>
<li><a href="#">Портфолио</a><span>|</span></li>
<li><a href="#">О нас</a><span>|</span></li>
<li><a href="#">Блог</a><span>|</span></li>
<li><a href="#">Контакты</a></li>
</ul>
if($(window).width() > 767){
$('.dropdown').hover(function(){
$('.dropdown-menu').css('display','block')
},
function(){
$('.dropdown-menu').css('display','none')
}
)
$('.li-sub-dropdown').hover(function(){
$('.sub-dropdown-menu').css('display','block')
},
function(){
$('.sub-dropdown-menu').css('display','none')
})
};
Answer the question
In order to leave comments, you need to log in
The issue with browser resize is very subtle. You need to write your own handler. Here is a classic version suitable for any event. Here presented for resize
// отлавливает события resize
var handleResizeEvents = function() {
var resizeLayout = debounce(_resizeEvents, 30);
$(window).resize(resizeLayout);
}
// выполнятся через 30мс после resize
var _resizeEvents = function() {
// здесь функция ховера
if ($(window).width() > 767) {
$('.dropdown').hover(function() {
$('.dropdown-menu').css('display', 'block')
},
function() {
$('.dropdown-menu').css('display', 'none')
}
)
$('.li-sub-dropdown').hover(function() {
$('.sub-dropdown-menu').css('display', 'block')
},
function() {
$('.sub-dropdown-menu').css('display', 'none')
})
};
}
// Функционал следящий за событиями (взято из underscore.js)
// copyright undersore.js
var debounce = function(func, wait, immediate) {
var timeout, args, context, timestamp, result;
return function() {
context = this;
args = arguments;
timestamp = new Date();
var later = function() {
var last = (new Date()) - timestamp;
if (last < wait) {
timeout = setTimeout(later, wait - last);
} else {
timeout = null;
if (!immediate) result = func.apply(context, args);
}
};
var callNow = immediate && !timeout;
if (!timeout) {
timeout = setTimeout(later, wait);
}
if (callNow) result = func.apply(context, args);
return result;
};
};
Because your script is initialized at high resolutions at the start, do
$().on('hover', function(){
if($(window).width() > 767){}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question