简体   繁体   中英

Jquery resize dynamic update?

I'm trying to get my window resize to work but I have to update the page every time to get it to work. Is there any way that this can update dynamic??

$(document).ready(function() {
  var $window = $(window);

  function checkWidth() {
    var window_size = $window.width();
    if(window_size> 1820){
      $('.22').addClass('size33');
      $('.22').removeClass('size22');
    } else {
      $('.22').removeClass('size33');
      $('.22').addClass('size22');
    }
  }

  // Execute on load
  checkWidth();

  // Bind event listener
  $(window).resize(checkWidth);
});
var div = document.body.selectElementbyId("div id")
window.addEventListener('resize', function() {
        var window_size = $window.width();

        if(window_size> 1820){
           $('.22').addClass('size33');
           $('.22').removeClass('size22');
        } else {
           $('.22').removeClass('size33');
           $('.22').addClass('size22');
        }
        document.getElementbyId("div id").style.width = window_size;
    }
}, true);

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