0

I have a script for a sliding panel woring as a menu. It works welllm but i have to apply a different margin-top depending on what screen resolution (mobile).

$(document).ready(function() {
$(".topMenuAction").click( function() {
    if ($("#openCloseIdentifier").is(":hidden")) {
        $("#slider").animate({ 
            marginTop: "-130px"
            }, 500 );
        $("#topMenuImage").html('<img src="img/icono-nav.png"/>');
        $("#openCloseIdentifier").show();
    } else {
        $("#slider").animate({ 
            marginTop: "0px"
            }, 500 );
        $("#topMenuImage").html('<img src="img/icono-cerrar.png"/>');
        $("#openCloseIdentifier").hide();
    }
});  

Thank you :)

Oscar
  • 1
  • 1

1 Answers1

2

If you know the widths

screenWidth = $( window ).width();

switch (screenWidth){
    case 760:
    newMargin = 100;
    break;
    case 420:
    newMargin = 75;
    break
}

if you want a range

if (screenWidth < 1000 && screenWidth >= 760){
    newMargin = 100;
}
else if (screenWidth < 760 && screenWidth >= 420){
    newMargin = 75;
}
else{
    newMargin = 250
}
Smith Smithy
  • 585
  • 6
  • 24