Changing a class name with jquery given a specific width range (media query)

前端 未结 3 919
一个人的身影
一个人的身影 2020-12-30 10:49

I have the following html that I am trying to modify:

I

3条回答
  •  臣服心动
    2020-12-30 11:21

    You can try this.

    $(window).resize(function(){
       console.log('resize called');
       var width = $(window).width();
       if(width >= 700 && width <= 900){
           $('#myelement').removeClass('width8').addClass('width6');
       }
       else{
           $('#myelement').removeClass('width6').addClass('width8');
       }
    })
    .resize();//trigger the resize event on page load.
    

提交回复
热议问题