2
I have a drop down menu along with the scroll. I used Jquery to add css attributes to make this happen. I don’t want this to happen when the site is less than 768px wide. That’s when it stands still
Media queries didn’t help me solve because these attributes were added resolution independent. So I tried the following:
$(window).scroll(function() {
if ($(window).width() < 760)
{
$('#menu').css({'position' : 'absolute'});
}
});
Or this
$(function() {
if ( $(window).width() < 760) {
$('#menu').css({'position' : 'relative'});
}
});
But it didn’t happen in both cases. I’m new to Jquery. How do I complement this code to work? I’m going the right way?
This is the code that makes my menu scroll
$(function() {
$(window).scroll(function()
{
var topo = $('#topo').height(); // altura do topo
var rodape = $('#rodape').height(); // altura do rodape
var scrollTop = $(window).scrollTop(); // qto foi rolado a barra
var tamPagina = $(document).height(); // altura da p?gina
if(scrollTop > topo){
$('#menu').css({'position' : 'fixed', 'top' : '0'});
}else{
$('#menu').css({'position' : 'relative', 'margin-top' : 0});
}
});
});
IS
absolute
really? Wouldn’t it befixed
?– Renan Gomes
I pasted the Absolute code by mistake, here I tried the same Fixed but didn’t stop the menu scroll.
– Anderson