{"id":689,"date":"2012-05-30T12:09:13","date_gmt":"2012-05-30T12:09:13","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=689"},"modified":"2012-05-30T12:09:13","modified_gmt":"2012-05-30T12:09:13","slug":"tutorial-jquery-image-rollover","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/tutorial-jquery-image-rollover\/","title":{"rendered":"jQuery Image Rollover Effect Example"},"content":{"rendered":"<p>If you have wondered if it is possible to create a \u00a0rollover for an image using jQuery, then the answer to it is: &#8220;Yes&#8221;! In this article by using a simple example, I am going to show you how to <em><strong>use \u00a0jQuery to create Image Rollover effect<\/strong><\/em>.<!--more--><\/p>\n<h2>Example of Image Roll Over Effect Using jQuery<\/h2>\n<p>Let&#8217;s look at the demo first:<\/p>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=689\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<p><strong>Before Rollover:<\/strong><\/p>\n<p><a href=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/uploads\/2012\/05\/img_default.png\" class=\"broken_link\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-thumbnail wp-image-694\" title=\"jQuery Image Rollover Effect - Before Rollover\" alt=\"\" src=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/uploads\/2012\/05\/img_default-150x150.png\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p><strong>After Rollover:<\/strong><\/p>\n<p><a href=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/uploads\/2012\/05\/img_roll.png\" class=\"broken_link\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-thumbnail wp-image-695\" title=\"jQuery Image Rollover Effect - After Rollover\" alt=\"\" src=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/uploads\/2012\/05\/img_roll-150x150.png\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p>For the sake of example, let&#8217;s assume that you have a main &#8220;container&#8221; div that contains both the images i.e the image that needs to be shown by default and the roll over image as well.<\/p>\n<h3>Example: Here is the complete source code<\/h3>\n<pre class=\"lang:xhtml decode:true\">&lt;!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\"&gt;\n&lt;html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"&gt;\n&lt;head&gt;\n&lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/&gt;\n&lt;title&gt;jQuery Image Rollover&lt;\/title&gt;\n&lt;script type=\"text\/javascript\" src=\"js\/jquery-1.8.2.min.js\"&gt;&lt;\/script&gt;\n&lt;style type=\"text\/css\"&gt;\n.container {\nwidth: 300px;\n}\n&lt;\/style&gt;\n&lt;\/head&gt;\n\n&lt;body&gt;\n\n&lt;div class=\"container\"&gt;\n&lt;img src=\"1.jpg\" width=\"300\" height=\"300\" class=\"img_default\"&gt;\n&lt;img src=\"2.jpg\" width=\"300\" height=\"300\" class=\"img_rollover\"&gt;\n&lt;\/div&gt;\n\n&lt;script type=\"text\/javascript\" language=\"javascript\" &gt;\n$(document).ready(function(){\n\n$('.img_rollover', $(this)).hide();\n\n$('.container').hover(\nfunction() {\n$('.img_default', $(this)).hide();\n$('.img_rollover', $(this)).show();\n},\nfunction() {\n$('.img_default', $(this)).show();\n$('.img_rollover', $(this)).hide();\n}\n);\n\n});\n&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<h5>Simple, isn&#8217;t it?<\/h5>\n<p>Do you know of any other ways to <em><strong>make Image rollover effect using jQuery<\/strong><\/em>? Feel free to suggest by commenting below.<\/p>\n<p>P.S: \u00a0If you would like to find out how to achieve Image Rollover effect using CSS, then read my article on\u00a0<a title=\"CSS Image Rollover with Example\" href=\"https:\/\/theextremewebdesigns.com\/blog\/css-image-rollover-with-example\/\" target=\"_blank\">CSS Image Rollover with Example<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have wondered if it is possible to create a \u00a0rollover for an image using jQuery, then the answer to it is: &#8220;Yes&#8221;! In this article by using a simple example, I am going to show you how to use \u00a0jQuery to create Image Rollover effect.<\/p>\n","protected":false},"author":1,"featured_media":395,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[23,20,13,22],"tags":[42,41,72],"class_list":["post-689","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery-tutorials","category-jquery-tips-and-tricks","category-tips-and-tricks","category-tutorials","tag-jquery-demos-2","tag-jquery-tips","tag-tutorials-jquery"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-b7","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/689","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=689"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/689\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}