Is it possible to listen to a “style change” event?

前端 未结 11 1231
南笙
南笙 2020-11-22 08:03

Is it possible to create an event listener in jQuery that can be bound to any style changes? For example, if I want to \"do\" something when an element changes dimensions, o

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 08:35

    How about jQuery cssHooks?

    Maybe I do not understand the question, but what you are searching for is easily done with cssHooks, without changing css() function.

    copy from documentation:

    (function( $ ) {
    
    // First, check to see if cssHooks are supported
    if ( !$.cssHooks ) {
      // If not, output an error message
      throw( new Error( "jQuery 1.4.3 or above is required for this plugin to work" ) );
    }
    
    // Wrap in a document ready call, because jQuery writes
    // cssHooks at this time and will blow away your functions
    // if they exist.
    $(function () {
      $.cssHooks[ "someCSSProp" ] = {
        get: function( elem, computed, extra ) {
          // Handle getting the CSS property
        },
        set: function( elem, value ) {
          // Handle setting the CSS value
        }
      };
    });
    
    })( jQuery ); 
    

    https://api.jquery.com/jQuery.cssHooks/

提交回复
热议问题