8

To have a gradient background on an element I do something like this:

.css('filter','progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#FFFFFF\', endColorstr=\'#'+event.backgroundColor+'\', gradientType=1)')
.css('background-image','-webkit-gradient(linear, left top, right bottom, color-stop(0.1, #FFFFFF), color-stop(0.99, #'+event.backgroundColor+'))')
.css('background-image','-moz-linear-gradient(top left, #FFFFFF 0%, #'+event.backgroundColor+' 100%)')
.css('background-image','-o-linear-gradient(top left, #FFFFFF 0%, #'+event.backgroundColor+' 100%)')

Now, isn't jQuery suppose to eliminate all the work related to cross-browser compatibility issues? is there any better way to do that. Without using any additional plugins?

10
  • 3
    Jquery will eliminate/reduce js related cross browser issues it won't fix your css cross browser problems. As for what i know jQuery wont fix this problem for you. Commented Apr 20, 2011 at 19:24
  • You could just define all of that in your stylesheet. Not sure why you are using jQuery, unless you need to do this dynamically or something. Commented Apr 20, 2011 at 19:25
  • 1
    Don't use "background-image:" - use "background:". Commented Apr 20, 2011 at 19:25
  • 3
    put all of these in a stylesheet under a class, then toggle the class with jquery. Commented Apr 20, 2011 at 19:38
  • 3
    @SteveCostello If you use the shortcut syntax background, then if you change any of the background properties later, for example background-position, then you can also overwrite the gradient you set in background. The CSS Specifications suggest not using shorthand codes anymore. Commented Apr 20, 2011 at 19:42

2 Answers 2

8

there is a jQuery plugin used to work with gradient. i have never used it but it looks simple

http://plugins.jquery.com/project/gradient

heres how to use it :

http://www.julien-verkest.fr/13/11/2007/jquery-gradient-le-plugin-qui-permet-de-creer-dynamiquement-des-backgrounds-degrades

or you could use use Gradientz

http://jquerystyle.com/2009/08/06/gradientz

Gradientz looks even more complete and easy to use. Up to you good luck buddy.

Sign up to request clarification or add additional context in comments.

4 Comments

Gradientz looks like a nice plugin :)
It does im gonna have to finda project to try it in! the jQuery community is so awesome theres tons of really nice plugins.
Yep sure is! And its growing every day :)
those sites seem down
4

Nope. jQuery doesn't have a native implementation of vendor-prefixes. Not very surprising, too; jQuery is a JavaScript library, designed to make JavaScript cross-browser.

Check out CSS3 Finalize for a plugin.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.