Trigger event using Jquery on CSS change?

后端 未结 3 1906
不思量自难忘°
不思量自难忘° 2020-12-19 01:38

I\'m curious is there an event listener or perhaps a way to construct a method that will trigger when a CSS change happens?

My stylesheet uses media queries and I wa

3条回答
  •  时光说笑
    2020-12-19 01:55

    I know this is old but I managed to solve it with this logic

        // set width and height of element that is controlled by the media query
        var page_width = $page.width();
        var page_height = $page.height();
    
    
        $window = $(window).resize(function(){
            if( $page.width() != page_width ) {
                // update page_width and height so it only executes your 
                // function when a change occurs
                page_width = $page.width();
                page_height = $page.height();
                // do something
                // ...
            }
        });
    

提交回复
热议问题