简体   繁体   中英

Jquery change script elements on browser width adjust

I'm trying to use matchMedia in Jquery so that the script will draw smallBlock when the browser is 479px wide or less and draw largeBlock on every other size.

Here is the full script code: The first part of the script is TweenMax and the second part is my script. https://jsfiddle.net/h0eu0edd/

You can see the rectangle being drawn on here ( http://imdarrien.com/# )

  function handleScreen(mql) {
   if (mql.matches) {
       smallBlock();
   } else {
       largeBlock();
   }
  }

There were a few syntax errors in the code you posted to jsfiddle.

Also, I changed the code to use $(document).ready instead of $(window).load as jsfiddle doesn't handle it.

See here: https://jsfiddle.net/w1xnsgcg/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM