I have a problem creating an event in jquery .. my code is this:
In THML there are no problems because it refers to an event .. I attach the code in jquery:
$("nav ul li a").click(function(e) {
e.preventDefault();
var target = $(this).attr("href");
$("html,body").animate({
scrollTop: $(target).offset().top
},2000,"easeOutQuint");
});
In this way, when I click on the nav entry, it takes me to the desired element ... here there is no problem.
Then I created a hamb that allows me to view the nav in full screen, it opens and closes quietly, here is the code.
$("#hamb").click(function(e) {
if( $(this).hasClass("on") ){
$(this).removeClass("on");
$("#full").stop().fadeIn(800);
$("#full ul li").addClass("down");
$(this).css("z-index", "20");
$("#hamb span:nth-of-type(1)").addClass("ruota1");
$("#hamb span:nth-of-type(2)").css("opacity", "0");
$("#hamb span:nth-of-type(3)").addClass("ruota3");
} else {
$(this).addClass("on");
$("#full").stop().fadeOut(300);
$("#full ul li").removeClass("down");
$(this).css("z-index", "10");
$("#hamb span:nth-of-type(1)").removeClass("ruota1");
$("#hamb span:nth-of-type(2)").css("opacity", "1");
$("#hamb span:nth-of-type(3)").removeClass("ruota3");
}
});
I want to make sure that when I click on a voice, the nav closes. I've already tried doing this(#full is the nav):
$("nav ul li a").click(function(e) {
e.preventDefault();
var target = $(this).attr("href");
$("html,body").animate({scrollTop: $(target).offset().top},2000,"easeOutQuint");
$("#full").stop().fadeOut(800);
});
It works, it disappears quietly..the problem is that the nav also disappears in the classic horizontal version .. how can I make sure that this rule is present only at a certain width of the window? So you only work with tablets and mobile phones? I tried with:
if ($(window).width() < 960) {
example....
}
But I can not use this rule well .. I can not, could someone help me?