True/False depending on screen size dynamically?












0















I'm following a guide that allows Google Map screen to disable scrolling depending on the screen size. The only part i'm struggling is to write a code that dynamically changes the True/False value when i resize the screen manually.



This is the website that I followed the instruction but I can't seem to write the correct syntax code to produce the dynamic true false value depending on the screen size https://coderwall.com/p/pgm8xa/disable-google-maps-scrolling-on-mobile-layout



Part of the code that i need to use:



$(window).resize()


And then:



setOptions()


So I'm struggling to combine them together.



I have tried something like this:



var dragging = $(window).width(function resize() {
if (dragging > 560) {
return true;
} else {
return false;
}
});









share|improve this question




















  • 2





    Why would "dragging" have both a boolean and numeric value (550)?

    – Diodeus - James MacFarlane
    Jan 2 at 14:53











  • my impression is that if val is true or false it will pass one of them to dragging? depending on the condition which in this case is the screen size is more 560 then true, else false

    – Marius
    Jan 2 at 14:54













  • You could replace your function core with: return (dragging > 560);

    – SPlatten
    Jan 2 at 14:57
















0















I'm following a guide that allows Google Map screen to disable scrolling depending on the screen size. The only part i'm struggling is to write a code that dynamically changes the True/False value when i resize the screen manually.



This is the website that I followed the instruction but I can't seem to write the correct syntax code to produce the dynamic true false value depending on the screen size https://coderwall.com/p/pgm8xa/disable-google-maps-scrolling-on-mobile-layout



Part of the code that i need to use:



$(window).resize()


And then:



setOptions()


So I'm struggling to combine them together.



I have tried something like this:



var dragging = $(window).width(function resize() {
if (dragging > 560) {
return true;
} else {
return false;
}
});









share|improve this question




















  • 2





    Why would "dragging" have both a boolean and numeric value (550)?

    – Diodeus - James MacFarlane
    Jan 2 at 14:53











  • my impression is that if val is true or false it will pass one of them to dragging? depending on the condition which in this case is the screen size is more 560 then true, else false

    – Marius
    Jan 2 at 14:54













  • You could replace your function core with: return (dragging > 560);

    – SPlatten
    Jan 2 at 14:57














0












0








0








I'm following a guide that allows Google Map screen to disable scrolling depending on the screen size. The only part i'm struggling is to write a code that dynamically changes the True/False value when i resize the screen manually.



This is the website that I followed the instruction but I can't seem to write the correct syntax code to produce the dynamic true false value depending on the screen size https://coderwall.com/p/pgm8xa/disable-google-maps-scrolling-on-mobile-layout



Part of the code that i need to use:



$(window).resize()


And then:



setOptions()


So I'm struggling to combine them together.



I have tried something like this:



var dragging = $(window).width(function resize() {
if (dragging > 560) {
return true;
} else {
return false;
}
});









share|improve this question
















I'm following a guide that allows Google Map screen to disable scrolling depending on the screen size. The only part i'm struggling is to write a code that dynamically changes the True/False value when i resize the screen manually.



This is the website that I followed the instruction but I can't seem to write the correct syntax code to produce the dynamic true false value depending on the screen size https://coderwall.com/p/pgm8xa/disable-google-maps-scrolling-on-mobile-layout



Part of the code that i need to use:



$(window).resize()


And then:



setOptions()


So I'm struggling to combine them together.



I have tried something like this:



var dragging = $(window).width(function resize() {
if (dragging > 560) {
return true;
} else {
return false;
}
});






javascript jquery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 14:52









Anuga

1,071719




1,071719










asked Jan 2 at 14:47









MariusMarius

888




888








  • 2





    Why would "dragging" have both a boolean and numeric value (550)?

    – Diodeus - James MacFarlane
    Jan 2 at 14:53











  • my impression is that if val is true or false it will pass one of them to dragging? depending on the condition which in this case is the screen size is more 560 then true, else false

    – Marius
    Jan 2 at 14:54













  • You could replace your function core with: return (dragging > 560);

    – SPlatten
    Jan 2 at 14:57














  • 2





    Why would "dragging" have both a boolean and numeric value (550)?

    – Diodeus - James MacFarlane
    Jan 2 at 14:53











  • my impression is that if val is true or false it will pass one of them to dragging? depending on the condition which in this case is the screen size is more 560 then true, else false

    – Marius
    Jan 2 at 14:54













  • You could replace your function core with: return (dragging > 560);

    – SPlatten
    Jan 2 at 14:57








2




2





Why would "dragging" have both a boolean and numeric value (550)?

– Diodeus - James MacFarlane
Jan 2 at 14:53





Why would "dragging" have both a boolean and numeric value (550)?

– Diodeus - James MacFarlane
Jan 2 at 14:53













my impression is that if val is true or false it will pass one of them to dragging? depending on the condition which in this case is the screen size is more 560 then true, else false

– Marius
Jan 2 at 14:54







my impression is that if val is true or false it will pass one of them to dragging? depending on the condition which in this case is the screen size is more 560 then true, else false

– Marius
Jan 2 at 14:54















You could replace your function core with: return (dragging > 560);

– SPlatten
Jan 2 at 14:57





You could replace your function core with: return (dragging > 560);

– SPlatten
Jan 2 at 14:57












4 Answers
4






active

oldest

votes


















1














The article you linked to is lacking important information as it fails to mention that $ is (presumably) jQuery. But you don't need jQuery at all.
What you can use instead is the MediaQueryList. It is similar to media queries in CSS, but it is a JavaScript API.



The following is an untested example of how you might use it with a MediaQueryList event listener. It sets the initial value and listens to changes to your media query with a handler that uses setOptions from the Google Maps API.



var mql = window.matchMedia('(min-width: 560px)');
var isDraggable = mql.matches;

var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
draggable: isDraggable
});
}

function mqChange(e) {
map.setOptions({draggable: !!e.matches});
}

mql.addListener(mqChange);





share|improve this answer


























  • hm getting: main.js:607 Uncaught TypeError: map.setOptions is not a function at MediaQueryList.mqChange

    – Marius
    Jan 2 at 15:43











  • Did you initialize Google Maps as per their documentation? Can you log map before map.setOptions is called?

    – str
    Jan 2 at 15:53











  • yep it's working now something is going wrong with what starts so i will fix it. but yep this worked thanks

    – Marius
    Jan 2 at 16:04











  • Found the issue i was declaring var map = ... inside function initMap(), basically writing var map = new google.maps.Map(document.getElementById('map')

    – Marius
    Jan 2 at 16:15



















1














You could add an event listener to the resize event and set a value of your variable whenever the size of the window is changed:



var dragging = false;
window.addEventListener('resize', function(event) {
dragging = window.innerWidth > 560;
});


Since you mentioned that you want to disable scrolling when the windows size extends a certain value, it might be easier to just do this. If you try it you can see in the console that the value changes whenever you resize your window):



window.addEventListener('resize', function(event) {
console.log(window.innerWidth);
if (window.innerWidth > 560) {
// disable scrolling or do whatever you want to do
}
});


BTW, in your code you do this:



 if (dragging > 560) {
return true;
} else {
return false;
}


You can simplify this to:



return dragging > 560


Which is exactly the same.






share|improve this answer


























  • Does not work when resizing screen dynamically

    – Marius
    Jan 2 at 14:58











  • what do you mean by "dynamically"?

    – Tagas
    Jan 2 at 14:59











  • the simplify is good, but in this case i'm still looking when i resize screen myself on desktop for it to disable scroll on small screen.

    – Marius
    Jan 2 at 14:59











  • when i drag window screen and resize it

    – Marius
    Jan 2 at 15:00











  • I adjusted the answer, please try and use the code and you can see in the console that it does work :)

    – Tagas
    Jan 2 at 15:06



















0














You can use this function to get the width and height on a resize of the screen.



$(window).resize(function() {
$windowWidth = $(window).width();
$windowHeight = $(window).height();
// run other functions or code
});


But, if you want to only show/hide a html element based on the screen size, you can also use plain html/css.



<div id="maps"></div>


Css:



@media only screen and (max-width: 560px) {
#maps {
display: none;
}
}





share|improve this answer



















  • 1





    no no, i don't need to hide elements, i need to disable scroll functionality depending on screen size.

    – Marius
    Jan 2 at 14:56






  • 1





    In that case just use CSS. Media queries and overflow: hidden should work

    – Rory McCrossan
    Jan 2 at 15:03



















0














you can use the matchMedia function to run a callback whenever the media query status is changing



var mql = window.matchMedia('(min-width: 700px)');

function mediaHandler(e) {
if (e.matches) {
/* the viewport is more than 700 pixels wide */
} else {
/* the viewport is 700 pixels wide or less */
}
}

mql.addListener(mediaHandler);





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008372%2ftrue-false-depending-on-screen-size-dynamically%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The article you linked to is lacking important information as it fails to mention that $ is (presumably) jQuery. But you don't need jQuery at all.
    What you can use instead is the MediaQueryList. It is similar to media queries in CSS, but it is a JavaScript API.



    The following is an untested example of how you might use it with a MediaQueryList event listener. It sets the initial value and listens to changes to your media query with a handler that uses setOptions from the Google Maps API.



    var mql = window.matchMedia('(min-width: 560px)');
    var isDraggable = mql.matches;

    var map;
    function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
    draggable: isDraggable
    });
    }

    function mqChange(e) {
    map.setOptions({draggable: !!e.matches});
    }

    mql.addListener(mqChange);





    share|improve this answer


























    • hm getting: main.js:607 Uncaught TypeError: map.setOptions is not a function at MediaQueryList.mqChange

      – Marius
      Jan 2 at 15:43











    • Did you initialize Google Maps as per their documentation? Can you log map before map.setOptions is called?

      – str
      Jan 2 at 15:53











    • yep it's working now something is going wrong with what starts so i will fix it. but yep this worked thanks

      – Marius
      Jan 2 at 16:04











    • Found the issue i was declaring var map = ... inside function initMap(), basically writing var map = new google.maps.Map(document.getElementById('map')

      – Marius
      Jan 2 at 16:15
















    1














    The article you linked to is lacking important information as it fails to mention that $ is (presumably) jQuery. But you don't need jQuery at all.
    What you can use instead is the MediaQueryList. It is similar to media queries in CSS, but it is a JavaScript API.



    The following is an untested example of how you might use it with a MediaQueryList event listener. It sets the initial value and listens to changes to your media query with a handler that uses setOptions from the Google Maps API.



    var mql = window.matchMedia('(min-width: 560px)');
    var isDraggable = mql.matches;

    var map;
    function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
    draggable: isDraggable
    });
    }

    function mqChange(e) {
    map.setOptions({draggable: !!e.matches});
    }

    mql.addListener(mqChange);





    share|improve this answer


























    • hm getting: main.js:607 Uncaught TypeError: map.setOptions is not a function at MediaQueryList.mqChange

      – Marius
      Jan 2 at 15:43











    • Did you initialize Google Maps as per their documentation? Can you log map before map.setOptions is called?

      – str
      Jan 2 at 15:53











    • yep it's working now something is going wrong with what starts so i will fix it. but yep this worked thanks

      – Marius
      Jan 2 at 16:04











    • Found the issue i was declaring var map = ... inside function initMap(), basically writing var map = new google.maps.Map(document.getElementById('map')

      – Marius
      Jan 2 at 16:15














    1












    1








    1







    The article you linked to is lacking important information as it fails to mention that $ is (presumably) jQuery. But you don't need jQuery at all.
    What you can use instead is the MediaQueryList. It is similar to media queries in CSS, but it is a JavaScript API.



    The following is an untested example of how you might use it with a MediaQueryList event listener. It sets the initial value and listens to changes to your media query with a handler that uses setOptions from the Google Maps API.



    var mql = window.matchMedia('(min-width: 560px)');
    var isDraggable = mql.matches;

    var map;
    function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
    draggable: isDraggable
    });
    }

    function mqChange(e) {
    map.setOptions({draggable: !!e.matches});
    }

    mql.addListener(mqChange);





    share|improve this answer















    The article you linked to is lacking important information as it fails to mention that $ is (presumably) jQuery. But you don't need jQuery at all.
    What you can use instead is the MediaQueryList. It is similar to media queries in CSS, but it is a JavaScript API.



    The following is an untested example of how you might use it with a MediaQueryList event listener. It sets the initial value and listens to changes to your media query with a handler that uses setOptions from the Google Maps API.



    var mql = window.matchMedia('(min-width: 560px)');
    var isDraggable = mql.matches;

    var map;
    function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
    draggable: isDraggable
    });
    }

    function mqChange(e) {
    map.setOptions({draggable: !!e.matches});
    }

    mql.addListener(mqChange);






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 2 at 15:15

























    answered Jan 2 at 15:07









    strstr

    18.2k65679




    18.2k65679













    • hm getting: main.js:607 Uncaught TypeError: map.setOptions is not a function at MediaQueryList.mqChange

      – Marius
      Jan 2 at 15:43











    • Did you initialize Google Maps as per their documentation? Can you log map before map.setOptions is called?

      – str
      Jan 2 at 15:53











    • yep it's working now something is going wrong with what starts so i will fix it. but yep this worked thanks

      – Marius
      Jan 2 at 16:04











    • Found the issue i was declaring var map = ... inside function initMap(), basically writing var map = new google.maps.Map(document.getElementById('map')

      – Marius
      Jan 2 at 16:15



















    • hm getting: main.js:607 Uncaught TypeError: map.setOptions is not a function at MediaQueryList.mqChange

      – Marius
      Jan 2 at 15:43











    • Did you initialize Google Maps as per their documentation? Can you log map before map.setOptions is called?

      – str
      Jan 2 at 15:53











    • yep it's working now something is going wrong with what starts so i will fix it. but yep this worked thanks

      – Marius
      Jan 2 at 16:04











    • Found the issue i was declaring var map = ... inside function initMap(), basically writing var map = new google.maps.Map(document.getElementById('map')

      – Marius
      Jan 2 at 16:15

















    hm getting: main.js:607 Uncaught TypeError: map.setOptions is not a function at MediaQueryList.mqChange

    – Marius
    Jan 2 at 15:43





    hm getting: main.js:607 Uncaught TypeError: map.setOptions is not a function at MediaQueryList.mqChange

    – Marius
    Jan 2 at 15:43













    Did you initialize Google Maps as per their documentation? Can you log map before map.setOptions is called?

    – str
    Jan 2 at 15:53





    Did you initialize Google Maps as per their documentation? Can you log map before map.setOptions is called?

    – str
    Jan 2 at 15:53













    yep it's working now something is going wrong with what starts so i will fix it. but yep this worked thanks

    – Marius
    Jan 2 at 16:04





    yep it's working now something is going wrong with what starts so i will fix it. but yep this worked thanks

    – Marius
    Jan 2 at 16:04













    Found the issue i was declaring var map = ... inside function initMap(), basically writing var map = new google.maps.Map(document.getElementById('map')

    – Marius
    Jan 2 at 16:15





    Found the issue i was declaring var map = ... inside function initMap(), basically writing var map = new google.maps.Map(document.getElementById('map')

    – Marius
    Jan 2 at 16:15













    1














    You could add an event listener to the resize event and set a value of your variable whenever the size of the window is changed:



    var dragging = false;
    window.addEventListener('resize', function(event) {
    dragging = window.innerWidth > 560;
    });


    Since you mentioned that you want to disable scrolling when the windows size extends a certain value, it might be easier to just do this. If you try it you can see in the console that the value changes whenever you resize your window):



    window.addEventListener('resize', function(event) {
    console.log(window.innerWidth);
    if (window.innerWidth > 560) {
    // disable scrolling or do whatever you want to do
    }
    });


    BTW, in your code you do this:



     if (dragging > 560) {
    return true;
    } else {
    return false;
    }


    You can simplify this to:



    return dragging > 560


    Which is exactly the same.






    share|improve this answer


























    • Does not work when resizing screen dynamically

      – Marius
      Jan 2 at 14:58











    • what do you mean by "dynamically"?

      – Tagas
      Jan 2 at 14:59











    • the simplify is good, but in this case i'm still looking when i resize screen myself on desktop for it to disable scroll on small screen.

      – Marius
      Jan 2 at 14:59











    • when i drag window screen and resize it

      – Marius
      Jan 2 at 15:00











    • I adjusted the answer, please try and use the code and you can see in the console that it does work :)

      – Tagas
      Jan 2 at 15:06
















    1














    You could add an event listener to the resize event and set a value of your variable whenever the size of the window is changed:



    var dragging = false;
    window.addEventListener('resize', function(event) {
    dragging = window.innerWidth > 560;
    });


    Since you mentioned that you want to disable scrolling when the windows size extends a certain value, it might be easier to just do this. If you try it you can see in the console that the value changes whenever you resize your window):



    window.addEventListener('resize', function(event) {
    console.log(window.innerWidth);
    if (window.innerWidth > 560) {
    // disable scrolling or do whatever you want to do
    }
    });


    BTW, in your code you do this:



     if (dragging > 560) {
    return true;
    } else {
    return false;
    }


    You can simplify this to:



    return dragging > 560


    Which is exactly the same.






    share|improve this answer


























    • Does not work when resizing screen dynamically

      – Marius
      Jan 2 at 14:58











    • what do you mean by "dynamically"?

      – Tagas
      Jan 2 at 14:59











    • the simplify is good, but in this case i'm still looking when i resize screen myself on desktop for it to disable scroll on small screen.

      – Marius
      Jan 2 at 14:59











    • when i drag window screen and resize it

      – Marius
      Jan 2 at 15:00











    • I adjusted the answer, please try and use the code and you can see in the console that it does work :)

      – Tagas
      Jan 2 at 15:06














    1












    1








    1







    You could add an event listener to the resize event and set a value of your variable whenever the size of the window is changed:



    var dragging = false;
    window.addEventListener('resize', function(event) {
    dragging = window.innerWidth > 560;
    });


    Since you mentioned that you want to disable scrolling when the windows size extends a certain value, it might be easier to just do this. If you try it you can see in the console that the value changes whenever you resize your window):



    window.addEventListener('resize', function(event) {
    console.log(window.innerWidth);
    if (window.innerWidth > 560) {
    // disable scrolling or do whatever you want to do
    }
    });


    BTW, in your code you do this:



     if (dragging > 560) {
    return true;
    } else {
    return false;
    }


    You can simplify this to:



    return dragging > 560


    Which is exactly the same.






    share|improve this answer















    You could add an event listener to the resize event and set a value of your variable whenever the size of the window is changed:



    var dragging = false;
    window.addEventListener('resize', function(event) {
    dragging = window.innerWidth > 560;
    });


    Since you mentioned that you want to disable scrolling when the windows size extends a certain value, it might be easier to just do this. If you try it you can see in the console that the value changes whenever you resize your window):



    window.addEventListener('resize', function(event) {
    console.log(window.innerWidth);
    if (window.innerWidth > 560) {
    // disable scrolling or do whatever you want to do
    }
    });


    BTW, in your code you do this:



     if (dragging > 560) {
    return true;
    } else {
    return false;
    }


    You can simplify this to:



    return dragging > 560


    Which is exactly the same.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 2 at 15:06

























    answered Jan 2 at 14:55









    TagasTagas

    581517




    581517













    • Does not work when resizing screen dynamically

      – Marius
      Jan 2 at 14:58











    • what do you mean by "dynamically"?

      – Tagas
      Jan 2 at 14:59











    • the simplify is good, but in this case i'm still looking when i resize screen myself on desktop for it to disable scroll on small screen.

      – Marius
      Jan 2 at 14:59











    • when i drag window screen and resize it

      – Marius
      Jan 2 at 15:00











    • I adjusted the answer, please try and use the code and you can see in the console that it does work :)

      – Tagas
      Jan 2 at 15:06



















    • Does not work when resizing screen dynamically

      – Marius
      Jan 2 at 14:58











    • what do you mean by "dynamically"?

      – Tagas
      Jan 2 at 14:59











    • the simplify is good, but in this case i'm still looking when i resize screen myself on desktop for it to disable scroll on small screen.

      – Marius
      Jan 2 at 14:59











    • when i drag window screen and resize it

      – Marius
      Jan 2 at 15:00











    • I adjusted the answer, please try and use the code and you can see in the console that it does work :)

      – Tagas
      Jan 2 at 15:06

















    Does not work when resizing screen dynamically

    – Marius
    Jan 2 at 14:58





    Does not work when resizing screen dynamically

    – Marius
    Jan 2 at 14:58













    what do you mean by "dynamically"?

    – Tagas
    Jan 2 at 14:59





    what do you mean by "dynamically"?

    – Tagas
    Jan 2 at 14:59













    the simplify is good, but in this case i'm still looking when i resize screen myself on desktop for it to disable scroll on small screen.

    – Marius
    Jan 2 at 14:59





    the simplify is good, but in this case i'm still looking when i resize screen myself on desktop for it to disable scroll on small screen.

    – Marius
    Jan 2 at 14:59













    when i drag window screen and resize it

    – Marius
    Jan 2 at 15:00





    when i drag window screen and resize it

    – Marius
    Jan 2 at 15:00













    I adjusted the answer, please try and use the code and you can see in the console that it does work :)

    – Tagas
    Jan 2 at 15:06





    I adjusted the answer, please try and use the code and you can see in the console that it does work :)

    – Tagas
    Jan 2 at 15:06











    0














    You can use this function to get the width and height on a resize of the screen.



    $(window).resize(function() {
    $windowWidth = $(window).width();
    $windowHeight = $(window).height();
    // run other functions or code
    });


    But, if you want to only show/hide a html element based on the screen size, you can also use plain html/css.



    <div id="maps"></div>


    Css:



    @media only screen and (max-width: 560px) {
    #maps {
    display: none;
    }
    }





    share|improve this answer



















    • 1





      no no, i don't need to hide elements, i need to disable scroll functionality depending on screen size.

      – Marius
      Jan 2 at 14:56






    • 1





      In that case just use CSS. Media queries and overflow: hidden should work

      – Rory McCrossan
      Jan 2 at 15:03
















    0














    You can use this function to get the width and height on a resize of the screen.



    $(window).resize(function() {
    $windowWidth = $(window).width();
    $windowHeight = $(window).height();
    // run other functions or code
    });


    But, if you want to only show/hide a html element based on the screen size, you can also use plain html/css.



    <div id="maps"></div>


    Css:



    @media only screen and (max-width: 560px) {
    #maps {
    display: none;
    }
    }





    share|improve this answer



















    • 1





      no no, i don't need to hide elements, i need to disable scroll functionality depending on screen size.

      – Marius
      Jan 2 at 14:56






    • 1





      In that case just use CSS. Media queries and overflow: hidden should work

      – Rory McCrossan
      Jan 2 at 15:03














    0












    0








    0







    You can use this function to get the width and height on a resize of the screen.



    $(window).resize(function() {
    $windowWidth = $(window).width();
    $windowHeight = $(window).height();
    // run other functions or code
    });


    But, if you want to only show/hide a html element based on the screen size, you can also use plain html/css.



    <div id="maps"></div>


    Css:



    @media only screen and (max-width: 560px) {
    #maps {
    display: none;
    }
    }





    share|improve this answer













    You can use this function to get the width and height on a resize of the screen.



    $(window).resize(function() {
    $windowWidth = $(window).width();
    $windowHeight = $(window).height();
    // run other functions or code
    });


    But, if you want to only show/hide a html element based on the screen size, you can also use plain html/css.



    <div id="maps"></div>


    Css:



    @media only screen and (max-width: 560px) {
    #maps {
    display: none;
    }
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 2 at 14:55









    R PelzerR Pelzer

    693826




    693826








    • 1





      no no, i don't need to hide elements, i need to disable scroll functionality depending on screen size.

      – Marius
      Jan 2 at 14:56






    • 1





      In that case just use CSS. Media queries and overflow: hidden should work

      – Rory McCrossan
      Jan 2 at 15:03














    • 1





      no no, i don't need to hide elements, i need to disable scroll functionality depending on screen size.

      – Marius
      Jan 2 at 14:56






    • 1





      In that case just use CSS. Media queries and overflow: hidden should work

      – Rory McCrossan
      Jan 2 at 15:03








    1




    1





    no no, i don't need to hide elements, i need to disable scroll functionality depending on screen size.

    – Marius
    Jan 2 at 14:56





    no no, i don't need to hide elements, i need to disable scroll functionality depending on screen size.

    – Marius
    Jan 2 at 14:56




    1




    1





    In that case just use CSS. Media queries and overflow: hidden should work

    – Rory McCrossan
    Jan 2 at 15:03





    In that case just use CSS. Media queries and overflow: hidden should work

    – Rory McCrossan
    Jan 2 at 15:03











    0














    you can use the matchMedia function to run a callback whenever the media query status is changing



    var mql = window.matchMedia('(min-width: 700px)');

    function mediaHandler(e) {
    if (e.matches) {
    /* the viewport is more than 700 pixels wide */
    } else {
    /* the viewport is 700 pixels wide or less */
    }
    }

    mql.addListener(mediaHandler);





    share|improve this answer




























      0














      you can use the matchMedia function to run a callback whenever the media query status is changing



      var mql = window.matchMedia('(min-width: 700px)');

      function mediaHandler(e) {
      if (e.matches) {
      /* the viewport is more than 700 pixels wide */
      } else {
      /* the viewport is 700 pixels wide or less */
      }
      }

      mql.addListener(mediaHandler);





      share|improve this answer


























        0












        0








        0







        you can use the matchMedia function to run a callback whenever the media query status is changing



        var mql = window.matchMedia('(min-width: 700px)');

        function mediaHandler(e) {
        if (e.matches) {
        /* the viewport is more than 700 pixels wide */
        } else {
        /* the viewport is 700 pixels wide or less */
        }
        }

        mql.addListener(mediaHandler);





        share|improve this answer













        you can use the matchMedia function to run a callback whenever the media query status is changing



        var mql = window.matchMedia('(min-width: 700px)');

        function mediaHandler(e) {
        if (e.matches) {
        /* the viewport is more than 700 pixels wide */
        } else {
        /* the viewport is 700 pixels wide or less */
        }
        }

        mql.addListener(mediaHandler);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 15:01









        Olivier BoisséOlivier Boissé

        3,5401026




        3,5401026






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008372%2ftrue-false-depending-on-screen-size-dynamically%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas