Home     |      Learn AJAX     |      Forum     |      Register     |      Submit Resource     |      Submit Article      |      Contact Us

Home AJAX-Tips
 

Loading CSS Gradients in Canvas

 

Designing an Ajax based application often requires smart coding as it will require additional JavaScript functions instead of plain HTML backgrounds. In using JavaScript, developers will be able to add another function that might interact with the application while providing the application a relatively better look.


An option for developers to achieve this background layout without requiring too much information from the local application is to use external sources. But this setting is always faced with problems especially for same-origin policy. Using 3rd party background requires extra tweaking so that the application will continue despite its use of outside source.


Internal Background with Gradients


A good option for developers who wanted to load their background internally is to use gradients. Developers should consider looking for a background tool that will not require too much from the users and application but just enough to have a great look. Using gradient actually fits that description as it’s light enough to be implemented in various browsers (Safari and Chrome). The only challenge is on Firefox, Opera and IE which does not recognize gradients.


A solution was presented to this problem by using two tools related to JavaScript development: CSS and HTML 5. To be specific, developers will load the gradients background with the help of CSS. Through CSS, loading the background will be a lot faster since it will be loaded internally. While external CSS might work as efficient as internal CSS, gradients provide a complicated scenario for a background especially on Firefox, IE and Opera.


To solve that lingering problem, developers can use canvas and load it as HTML 5. This can be possible because gradients can be used loaded in canvas which will be ultimately loaded in HTML 5. By using HTML 5, developers will be able to create a JavaScript tool that can easily used as a background.


By transforming gradients into HTML 5 and loading the background with the help of CSS, developers will be able to have a great looking background. Gradients do not simply offer a colorful background by a wide range of options on how the colors are rendered. All these features can be achieved by developers without any assistance from outside application.


Challenges


There is one problem developers have to deal with when using this relatively complicated technique - readability of additional elements. When the tool is converted to HTML 5 as a JavaScript tool, some elements might not work as expected simply because it implements gradients - something that only Webkit can fully work with.


Compared to SVG


Of course, developers can always do away with all the troubles with gradients to canvas and then to HTML 5 by using SVG. It's easier to implement, very familiar to developers and can be as lightweight (even lighter) to gradients. However, using SVG as the background can be too simplistic to many developers. SVG do not provide a lot of customization opportunity for developers.


Full example, coding, and demonstration can be found in this post. The code is light (12k) so implementation will drag additional resources.



Read Next: JS Liquid Image



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links