This post is not exactly about WCS. But I have spent several sleepless nights to implement this functionality. Tried a lot of approaches , read a lot of blogs but each approach had some issue or other especially IE!
Here is an approach to implement the image roll-overs and broken image handling using zero-size handling and jQuery.
This approach works for all major browsers - IE , FF , Chrome , Safari and also saves us from the ugly IE "StackOverFlow" error in IE (which might happen if an infinte loop is accidently due to "onerror" handling of image)
Here is an approach to implement the image roll-overs and broken image handling using zero-size handling and jQuery.
This approach works for all major browsers - IE , FF , Chrome , Safari and also saves us from the ugly IE "StackOverFlow" error in IE (which might happen if an infinte loop is accidently due to "onerror" handling of image)
Image Roll Over | |||
Problem DescriptionImage Rollover functionality are becoming quite common in various web-sites since they kind of put life to your website. They are generally easy to implement and involve changing the source of the img on hover and on mouse out. However , there could be scenarios when the toggle image ( the image to be displayed on mouse hover ) is not available either on the local server or third party image servers such as Scene7. Such scenarios need to be handled. Most often you can use the onerror attribute to assign alternate image from the server to be displayed if the toggle image is not available. The requirement that we have is - There are two preferred images to be shown on toggle. If preferredImage1 is not found , look for preferredImage2. If preferredImage2 is not available , then show the original image (effectively dont toggle) | |||
Base Image |
Preferred rollover image |
Alternate rollover image |
|
Working Demo | |||
Scenario 1 : If all images are found, first preferred image will be black creme box |
Scenario 2 : The first preferred image not found at online src, second preferred image - white creme box |
Scenario 3 : None alternate images found , no toggle |
|
SolutionThis solution is based on zero height detection using jQuery for the missing images.
| |||
Sample Code | |||
Disclaimer: The L'Oreal product images are just used as samples for the demo and this blog in no way endorses any products or websites. The image URLs were returned by the Google Images search results -
|
|||
Author : Neha Das |
No comments:
Post a Comment