Note that there are some explanatory texts on larger screens.

plurals
  1. PODestroying a function when exiting a matched breakpoint with enquire.js
    primarykey
    data
    text
    <p>This is probably basic to most reading, but I can't seem to figure it out. </p> <p>I have a little test function that I want to execute if under a certain width. When the screen rotates or gets resized above that width, I want the function to cease to work. Here is some example code for simplicity sake.</p> <pre><code>enquire.register("screen and (max-width:500px)",{ match : function() { $(".block .block-title").click(function(){ alert("Hello World!"); }); } }).listen(); </code></pre> <p>So if the page loads above 500px, it works as intended. Clicking won't execute. If the page loads at 500px or below, the click function executes. Only problem is that if you resize the viewport or change orientation to something above 500px, the function still executes. I'd like to be able to disable that. </p> <p>The real world scenario I'm actually trying to do here is I have an un-ordered list of 4 items. Above a certain width they are displayed right away. If under a certain width, I just want to hide them and on click show them. I know there are a few ways to do it (.toggle(), .toggleClass("myclass"), etc).</p> <p>I have done this a bunch of times but I always get caught with the entering / exiting break points and things not being reset, or working as intended. Usually it doesn't matter, but lately in some of my use cases it has mattered.</p> <p>I know of the unmatch option but I'm not sure how to really kill the matched function above.</p> <pre><code>enquire.register("screen and (max-width:500px)",{ match : function() { $(".block .block-title").click(function(){ alert("Hello World!"); }); }, { unmatch : function() { // what do I do here do kill above? } } }).listen(); </code></pre> <p>Any help would be appreciated. I am pretty sure it will help my current situation but will also help me expand my knowledge of enquire.js for other things.</p> <p>Thanks.</p> <p>edit: I forgot to mention... if you load the page under 500px, then resize or orientate wider then 500px, then go BACK under 500px, the click function won't work again.. which confuses me also. I basically was hoping it would work no matter what when under 500px, and not work at all when over 500px. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload