0

I need to adjust a tab link location when the browser gets below a certain width. I've looked around and haven't been able to make this work. It never readjusts. Here is the code I'm using

$(window).resize(
  function pageResize() {
  $screenSize = $(window).width();
  if($(screenSize) < 546){
    $("#ce").css("left", "80.5%");
    $("#ce").css("marginLeft", "-70px");
  }
});
5
  • 2
    Why not use media queries? Commented Apr 9, 2015 at 17:24
  • 2
    In the if statement instead of $(screenSize) use $screenSize. Commented Apr 9, 2015 at 17:25
  • The if condition should be if($screenSize...) Commented Apr 9, 2015 at 17:25
  • Please check if it even runs (as in if your function gets called and your if is stepped into) - you can do it either with breakpoints (in chrome) or by placing alerts or console.log. I think you cannot have a named function as an argument, but maybe I'm wrong. Commented Apr 9, 2015 at 17:26
  • This is a simple typo; closing the question as such. Commented Apr 9, 2015 at 19:18

3 Answers 3

2

You have a bug:

$screenSize = $(window).width();
    if($(screenSize) < 546){

You don't want if ($(screenSize)) you want: if ($screenSize).

Edit: and yes. Media queries makes WAAAAAY more sense than doing this with jQuery.

Sign up to request clarification or add additional context in comments.

1 Comment

I got it. Thanks :) at first it wasn't working, but then I realized that my file wasn't named properly in the html file lol
0

Almost :) Try this:

$(window).resize(function () {
    $screenSize = $(window).width();
    if($screenSize < 546){
        $("#ce").css("left", "80.5%");
        $("#ce").css("marginLeft", "-70px");
    }
});

Comments

0

I've also came across similar situation and here is the code I have implemented. I hope it will give you some idea.

$(document).ready(function () {   

        $(window).resize(function () {

            var navHeader = $('.header-container');

            var minHeight = 96;

            if (navHeader.height() > 90)
               minHeight = navHeader.height();

            $('.main-container').css('margin-top', minHeight + 10);
        });  

    });

If you are not seeing the expected result, check what values you are getting in $screenSize.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.