Web and SEO Professional
Jquery Image rollover with demo
I have given a code in my earlier post for jquery image rollover. Now here are the final code and guide how to use this code.
- you need to creative two image ie: one for normal state and one for active/rollover state. name it like imagename.gif and imagename_active.gif.
- put your image in your HTML document.
- put all your image in normal state. remember to keep the active state image in same folder.
- include jquery latest script from jquery website and include script on your head section.
- copy below code and paste after jquery include. (you can put this code in common include file and include after jquery include.)
- don’t forget to change “#nav td” with your a element parent element in below script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | function getLeaf(url) { var splited=url.split('?');// remove all the parameter from url url=splited[0]; return url.substring(url.lastIndexOf("/")+1);// return file name without domain and path } jQuery.fn.extend({ enter: function() {//plugins creation return this.each(function() { var pth = $(this).find("img")[0]; //alert($(this).children().attr("href")); if($(this).children().attr("href")==getLeaf(document.location.href)){// check that the link url and document url is same $(pth).attr("src",pth.src.replace(/.gif/g, '_active.gif')); } else{ $(this).hover(function(){ $(pth).attr("src",pth.src.replace(/.gif/g, '_active.gif'));// mouse over Image },function(){ $(pth).attr("src",pth.src.replace(/_active.gif/g, '.gif'));// mouse out image }); } }); } }); $(function(){ // Document is ready $("#nav td").enter();// call the function }); |
Jquery Image rollover demo download Let me know if you are not able to implement this code. I will happy to assist you.
| Print article | This entry was posted by Pankaj on March 24, 2009 at 3:39 am, and is filed under Web development. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
No trackbacks yet.
Network Solutions hosting issue or WordPress Security Flaw
about 4 months ago - No comments
My one of client is victim of this mass hack on network solution hosted blog. I am going to share some interesting fact about this vulnerability story. when our client contacted to Network Solution support tell them to buy SSL as your site is not secure. (6 April) I fixed theme files which is altered
Should My Company Have a Blog?
about 6 months ago - 1 comment
One of the most common misconceptions today is that a blog is meant for personal use. This couldn’t be further from the truth. A blog is so much more than a personal diary or a daily dose of someone’s personal opinions and ideas. A blog provides an opportunity for outsiders to become engaged and active.
Jquery solution for Radio Group in Umbraco mc_ed_form
about 10 months ago - No comments
Just tried Umbraco a dot net based open source system. following are some of my experience on that. I am totally new to dot net platform so i faced lots of problem to install Umbraco on shared server. After lots of research i found Umbraco is not compatible with networksolution and aplus.net shared hosting. Then
Successful Website Design Criteria
about 11 months ago - 4 comments
We believe you don’t start the design of a new or revised website by sitting down with the designer and coder of the website. Rather, we recommend you review the approaches, ideas, processes and other methods listed below to determine if they apply to your situation. Think about your audience. Are they looking for immediate
Mostly used programming languages and their programming advantages.
about 12 months ago - No comments
Nowadays, world wide clients are demanding for cost effective solutions along with high-performance speedy development. In recent internet marketing arena, designing a good website template and placing unique and relevant content is not enough for a profitable web businesses. Web programming is getting more value in terms of building flexible websites. Web programmers are skilled
When Should You Fire Your Website Designer
about 1 year ago - 4 comments
Your online business is not a wild crazy idea, but a source of income. Trust the right people to design your website. Your 17 year old nephew may be able to create your website or you can get a free one from several services…they might even be kind of pretty. In my research and experience,
My first Post from Windows Live Writer
about 1 year ago - 1 comment
I just installed windows live writer in my local machine. now we can write offline and post it when post is complete. I like this tool very good because we can see preview while editing. you can download Windows Live Writer from http://windowslivewriter.spaces.live.com/. you can include flicker digg and twitter feature while writing the post.
Grow traffic by adding social features to your site By Google
about 1 year ago - No comments
I just gone through Google Friend Connect. You can see Google Friend Connect Gadget on my website. Find at right bar of my Website. I will appreciate to join me. I also install Google Friend connect Plug-in for WordPress find it by submitting a comment. your comment will display with your profile photo and details.
Search of better CMS end with MODx
about 1 year ago - 1 comment
After 3 year of research on opensource cms i finaly decided use MODx for my all web need. I have done 2 website in Joomla, 4-5 website with typo3 and 4 WordPress blog. I was very satisfied with templating feature of typo3 specially there templovoila and tree structure of page view but when i use
Google’s New Products for this April
about 1 year ago - 1 comment
Following Are some new product from Google for April First 2009. Google has just launced their new browser Google Chrome with 3D. Visit announce here: http://www.google.com/intl/en/landing/chrome/cadie/. Please Let me know about you experience on Google Chrome with 3D. See you tube new layout while playing video or you can click on following link : http://www.youtube.com/watch?v=TjXE8kxyATY&flip=1

Loading...
about 6 months ago
If I replace all of the “gif” with “jpg” should it work with jpgs as well, or only gifs?
about 6 months ago
yes you can use jpg also change gif to jpg in code
about 6 months ago
Hi Pankaj, your code works great….
Sorry for my English and my ignorance in Js!
I’m trying to use it associated to a tabbed menu…
In this way the href for my image isn’t a new file but a div inside the document
So the line of your code that controls what image has to remain active does’t work…
if($(this).children().attr(“href”)==getLeaf(document.location.href))
and the rollover nerver stop (for the active link)….
So how can I change this line? (if it’s the right thing to change…)
Thank you very much
Elisa
about 6 months ago
are you creating a accessible tab like if you click on tab page url is like xyz.com/#tabname if so u can modify function getLeaf(url).
can you send me link of your page so i can provide a solution.
about 6 months ago
Thank you very much Pankaj!
The link for the page is
http://www.elisamonti.com/sviluppo/
Elisa
about 6 months ago
change
to
I hope this work for you.
about 6 months ago
Thank you very much…
I think there’s one more problem….
At the first loading the first panel is selected and the relative image link is correctly active…
Unfortunately when you click on other sections the correct section is loaded but the rollover isn’t correct….
Now i’ve uploaded the new version at http://www.elisamonti.com/sviluppo
Can you give me one more help? (if you can obviously)
…thank you so much…
Elisa
about 11 months ago
Can the image be called from the css instead of the html?
about 10 months ago
In css you can use css property for that
about 11 months ago
OMG, i have been searching for days and couldn’t find a simple answer to this. Thank-you so much! Just a quick question though… jquery look for the image within a div in the html. Is is possible to have it so it calls the image from css? I’m selling themes that are digitally downloaded and therefore i don’t want to include the http://mysite/image and would like to know if it can be done where it calls the image from the css eg. .mydiv { background:url ../styleImages/buttons/LPmore2.gif) no-repeat; }
Thanks
Jessie
about 12 months ago
Hi Pankaj,
Thank you for this code. It’s exactly what I have been looking for. In fact I can think of lots of situations when this could be very useful.
I was able to implement it with no problem, and the rollover effect works great.
For some reason the current page effect is not working on my site. I was hoping that you might offer some advice.
Here is the situation: It’s a wordpress site. I’m using list style navigation. Here’s a little bit of list nav code:
2
3
4
5
6
<ul>
<li><a href="<?php bloginfo('wpurl'); ?>"><img alt="" height="36px" src="<?php bloginfo('template_url'); ?>/images/home.gif" width="58"/></a></li>
<li><a href="<?php bloginfo('wpurl'); ?>/category/blog/" ><img src="<?php bloginfo('template_url'); ?>/images/blog.gif" height="36px" width="61" border="0"/></a></li>
Your demo works great, so the issue is with my implementation.
I get rollover when I call (#nav ul li) or (#nav ul li a). But neither way gives results in a current page effect.
Any advice on how to proceed with troubleshooting?
about 12 months ago
Change Line 4 in my code
change to
use at (#nav ul li)
Let me know its working?
about 12 months ago
Thank You!
That was the perfect fix.
I’ve bookmarked your blog, and look forward to reading more of your posts in the future.
about 1 year ago
An easier way to do this might be to make two images, one with a suffix “_on” and the other with the suffix of “_off”. Then paste this code
[code]
$(function() {
$("img.rollover").hover(
function () { this.src = this.src.replace("_off","_on");
},
function () { this.src = this.src.replace("_on","_off");
}
);
});
[/code]
And then you can just call rollovers on an image by adding ‘class=”rollover”‘, like
[code]
[/code]
about 1 year ago
you can see there are some other functionality in above script which is added.
Thanks for your contribution for easier version.
about 1 year ago
FANTASTIC!