Lets say I have the following CSS:
._gradient {
background-image: linear-gradient(top, #6AF 16px, #0032C8 24px);
background-image: -o-linear-gradient(top, #6AF 16px, #0032C8 24px);
background-image: -moz-linear-gradient(top, #6AF 16px, #0032C8 24px);
background-image: -webkit-linear-gradient(top, #6AF 16px, #0032C8 24px);
background-image: -ms-linear-gradient(top, #6AF 16px, #0032C8 24px);
background-image: -webkit-gradient(linear,left top,left bottom,color-stop(16px, #6AF),color-stop(24px, #0032C8));
}
Is there any way simple with Javascript or jQuery to read the values for the gradient position / direction / color?
obviously I could using Regular Expressions... the problem would lie in 'background-image' value returning a different value dependent on which browser was accessing the site: jsFiddle example
Basically now this led me to try just with the linear-gradient() value (aiming to do browser detect and apply the CSS with jQuery) but this returned the value 'none': jsFiddle example 2
Bare in mind my actual aim is to get these values dynamically with the script, not set them (although I'm willing for the solution to require me to do this).
EDIT FOR CLARIFICATION
I am looking for a way to read the values in a gradient, even if gradients are not supported. using $.cssHooks is not the answer due to the fact that if the property is nou supported, it returns the value 'none' which has no benefit what so ever.
color,positionanddirection. If the data is available tocssHooks, it will also be returned by$(elem).css('background-image')however you can't 'get' unsupported CSS values and the having toregexfor the different types of gradient supported in different browsers seems a little extreme.<div class="_gradient" linear-gradient="blah|blah"></div>then read the attr from the element $('._gradient').html($('._gradient').attr('linear-gradient')); or even better use an attribute for every value you need, top, rgba, etc.. i hope that helps !linear-gradientto be supported (in 50 years time...)