jQuery has the ability to create custom css properties .

And, for example, there is jQuery.transit , which uses cssHooks and I would like to add something to it.

I want the left and top CSS styles to work as x and y in jQuery.transit (where they turn into the css property transform: translate(x, y) ).

So, based on the documentation and the internal jQuery.transit API , I add the left and top properties to jQuery.transit :

 registerCssHook('left', true); /* some code */ setter { /* some code */ left: function(x) { this.set('translate', x, null); }, /* some code */ } /* some code */ getter { /* some code */ left: function() { return this._translateX || 0; }, /* some code */ } /* some code */ function registerCssHook(prop, isPixels) { // For certain properties, the 'px' should not be implied. if (!isPixels) { $.cssNumber[prop] = true; } $.transit.propertyMap[prop] = support.transform; $.cssHooks[prop] = { get: function(elem) { var t = $(elem).css('transit:transform'); return t.get(prop); }, set: function(elem, value) { var t = $(elem).css('transit:transform'); t.setFromString(prop, value); $(elem).css({ 'transit:transform': t }); } }; } 

And everything is almost perfect.
Now when I write:

 $('.class').css('left', '40px'); 

All elements with class class receive the following attributes:

  • transform: translate(x, y)
  • and .. for some reason left: x

Those. cssHook does not work by overriding , but by adding a handler .

And yes, jQuery.transit uses cssHooks , and not its own implementation.

Question: how to make redefinition?
How to replace the standard behavior of the css() function for left and top with what is described in cssHooks ?

  • It is necessary to correct the code, remove unnecessary. And do not go to the fortuneteller, even the scroll will be removed - Mr. Black
  • In the code, only that is relevant. If you look at how it is implemented in x in jQuery.transit and then in my code, you can see that there are no errors on my part. + I provide part of the code where the use of cssHooks is confirmed, and not the internal system. - user64675

0