Reputation: 3
I am working on a project and I am using bootstrap. I changed the default behavior of onClick
to hover
, on above 600 and equal to 600 size ( i.e >= 600 screensize) I want to execute the if body. And on less then 600 size of screen I don't want that code to be executed. BUT on less then 600 screen size if body is executed else part(which is by default on click method of bootstrap) is not executed.
if (screen.width >= 600) {
$(function(){
$('ul.nav li.dropdown').hover(function(){
$('.dropdown-menu', this).fadeIn();
},function(){
$('.dropdown-menu', this).fadeOut('fast');
});
});
}
Upvotes: 0
Views: 75
Reputation: 8226
Since explanation is not clear,Hope you want below piece of condition as per my understanding
function sizeFunc(){
var screenWidth = $(window).width();
$('ul.nav li.dropdown').hover(function(){
if(screenWidth >= 600){
$('.dropdown-menu', this).fadeIn();
}
},function(){
if(screenWidth < 600){
$('.dropdown-menu', this).fadeOut('fast');
}
});
}
$(function(){
sizeFunc();//on begin
$(window).on("resize",sizeFunc);//on every window size change
});
Upvotes: 1