Cross-Browser Transparent Image Display
Tuesday, December 18th, 2007Problem:
I am currently working on a map web site (www.eghlim.com) - city map of Tehran, Iran. The main problem is the big loading time. One thing I found, was the way we handled png images containing transparent parts: Firefox draws them properly, given the background image source, but IE needs a ‘filter’, griven the background image ‘null’.
The previous solution was to search for *.png images by javascript on page load, checking the browser and creating appropriate objects. As shown below:
The result was disappointing! IE freezes until the scripts are done, and then renders the whole page in 1 sec.
Answer:
I searched for 2 long days to find a better solution, tested several ways and finally found a nice work-around, By Rafael Lima. The essence is to use a css hack to define different styles for different browsers. In this case (showing a transparent png image in Firefox and IE):
Just adding css_browser_selector.js (as little as 10 lines of code) makes this possible. Fast and clean, isn’t it?
Mahdieh
P.S. Browser.js