Created
September 25, 2013 09:22
-
-
Save ifthenelse/6697163 to your computer and use it in GitHub Desktop.
jQuery script to manage rollover effect on img elements with a '.hoverable' class and two images (one with -normal and one with -hover suffix)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// init rollovers on images | |
imgRollover: function() { | |
var $app = this; | |
$.each($app.$hoverable, function(index, val) { | |
var $this = $(this); | |
// if the hoverable object is <img> | |
if (typeof $this === 'object' && $this.is("img")) { | |
var $obj = $this; | |
} | |
// if the hoverable object contains any <img> | |
if (typeof $obj === 'undefined' && !!$this.children("img").length) { | |
var $obj = $this.children("img"); | |
} | |
if (typeof $obj !== 'undefined' && !!$obj.length) { | |
$.each($obj, function(index, val) { | |
var $img = $(this); | |
if (typeof $img === 'object') { | |
var normal_src = $img.attr("src"), | |
hover_src = $img.attr("src").replace("-normal.", "-hover."); | |
if (!!normal_src.length) { | |
$this.hover(function(evt) { | |
console.log("Over"); | |
$img.attr("src", hover_src); | |
}, function(evt) { | |
console.log("Leave"); | |
$img.attr("src", normal_src); | |
}); | |
} | |
} | |
}); | |
} else { | |
return false; | |
} | |
}); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment