3
I’m working on a website that I want it to change the order of the read when the window is < 800px, and I implemented the code below. The problem is that it seems to be failing at random and sometimes even when the window is going back to over 800px, and the menu is no longer clickable. I don’t know if it’s because I’m conflicting with the animation you get when the window > 800px. Any hints? the site is on http://www.iwanttobesanta.com/news.php for anyone who wants to take a look.
function mouseEnterAnimation(allowAnimation) {
if (allowAnimation) {
$('#upBar, nav ul').stop(true).animate({
"height" : "60px"
}, 200);
$('nav ul li').stop(true).animate({
"padding-top" : "20px",
"padding-bottom" : "20px",
"height" : "60px"
}, 200);
$('#lang').stop(true).animate({
"padding-top" : "23px",
"padding-bottom" : "23px",
"height" : "60px"
}, 200);
$('#logo').stop(true).animate({
"margin-top" : "15px",
"margin-left" : "10px"
}, 200);
}
}
// Animação quando o rato sai de cima
function mouseLeaveAnimation(allowAnimation) {
if (allowAnimation) {
$('#upBar, nav ul').stop(true).animate({
"height": "45px"
}, 200, function() {
$('#upBar, nav ul').removeAttr("style");
});
$('nav ul li').stop(true).animate({
"padding-top" : "13px",
"padding-bottom" : "13px",
"height" : "45px"
}, 200, function() {
$('nav ul li').removeAttr('style');
});
$('#lang').stop(true).animate({
"padding-top" : "16px",
"padding-bottom" : "16px",
"height" : "45px"
}, 200);
$('#logo').stop(true).animate({
"margin-top" : "7px",
"margin-left" : "10px"
}, 200, function () {
$('#logo').removeAttr('style');
});
}
}
$(document).ready(function () {
var $topNav = $('#upBar, nav'),
allowAnimation = ($(window).width() >= 800);
$topNav.hover(
function(){
mouseEnterAnimation(allowAnimation);
},
function() {
mouseLeaveAnimation(allowAnimation);
}
);
if (!allowAnimation) {
$("nav ul").append($("li").get().reverse());
}
else {
}
$(window).resize(function() {
allowAnimation = ($(window).width() >= 800);
if (allowAnimation) {
$('nav ul').show();
}
else {
$('nav ul').hide();
$("nav ul").append($("li").get().reverse());
}
});
$("#btnMobile, #menu").on("click", function(){
$("nav ul").stop(true).slideToggle();
});
});
The whole problem is the part where you mess with the
li
and forgets that he’s surrounded by links<a href>
– Paulo Roberto Rosa
Yes I’ve been told about this, but I tried with the <a> inside the li and the links were only in the text, it was not that I intended
– Miguel
the
<a>
should not be inside the<li>
, the<a>
must be surrounding the<li>
in this way:<a href="#"> <li> Notícias </li> </a>
– Paulo Roberto Rosa
@Pauloroberto, this is not a valid construction. Markup out of compliance with the specifications can be rendered by the browser as it sees fit (and I have already witnessed incompatibilities between browsers exactly due to this construction). An element
<ul>
shall contain only elements<li>
. Elements<li>
on the other hand may contain links (which can be expanded to occupy the entire space of the<li>
as my comments in the reply.– Anthony Accioly
Got it, thank you very much
– Miguel
But how do I expand <a>? I’m trying and I can’t. http://jsfiddle.net/Dq6gM/
– Miguel
Miguel, that would be another question, but I’ll break your chain: http://jsfiddle.net/Dq6gM/1/.
display: block; height: 100;
worked for your fiddle.– Anthony Accioly
Thank you so much @Anthony
– Miguel