That's actually pretty simple. In that version of jQuery (and I think all, but this may have changed) the .hover() function allows one to pair at least two functions. It's the equivalent of mouseneter combined with mouseleave. But they only specified one function. In that case, it gets repeat for mouseleave. So, you can either add an empty function at the end, or some other function if you want something else to happen on mouseleave, or just change hover to mouseenter (probably the simplest):
Code:
jQuery(document).ready(function($){
$('#examples img').mouseenter(function () {
var $imgObj = $(this);
// class name
var sClass = $(this).attr('class');
// radius
var iRad = 0;
// interval
var iInt;
if (iInt) window.clearInterval(iInt);
// loop until end
iInt = window.setInterval(function() {
var iWidth = $imgObj.width();
var iHalfWidth = iWidth / 2;
var iHalfHeight = $imgObj.height() / 2;
if (sClass == 'type1') {
$imgObj.css('-webkit-mask', '-webkit-gradient(radial, '+iHalfWidth+' '+iHalfHeight+', '+ iRad +', '+iHalfWidth+' '+iHalfHeight+', '+ (iRad + 30) +', from(rgb(0, 0, 0)), color-stop(0.5, rgba(0, 0, 0, 0.2)), to(rgb(0, 0, 0)))');
} else if (sClass == 'type2') {
$imgObj.css('-webkit-mask', '-webkit-gradient(radial, '+iHalfHeight+' '+iHalfHeight+', '+ iRad +', '+iHalfHeight+' '+iHalfHeight+', '+ (iRad + 30) +', from(rgb(0, 0, 0)), color-stop(0.5, rgba(0, 0, 0, 0.2)), to(rgb(0, 0, 0)))');
}
// when radius is more than our width - stop loop
if (iRad > iWidth) {
window.clearInterval(iInt);
}
iRad+=2;
}, 10);
});
});
Alternate method (adding a dummy function at the end - scroll down to see it - as I say you can add stuff in there if you want, but empty is what stops the effect from repeating):
Code:
jQuery(document).ready(function($){
$('#examples img').hover(function () {
var $imgObj = $(this);
// class name
var sClass = $(this).attr('class');
// radius
var iRad = 0;
// interval
var iInt;
if (iInt) window.clearInterval(iInt);
// loop until end
iInt = window.setInterval(function() {
var iWidth = $imgObj.width();
var iHalfWidth = iWidth / 2;
var iHalfHeight = $imgObj.height() / 2;
if (sClass == 'type1') {
$imgObj.css('-webkit-mask', '-webkit-gradient(radial, '+iHalfWidth+' '+iHalfHeight+', '+ iRad +', '+iHalfWidth+' '+iHalfHeight+', '+ (iRad + 30) +', from(rgb(0, 0, 0)), color-stop(0.5, rgba(0, 0, 0, 0.2)), to(rgb(0, 0, 0)))');
} else if (sClass == 'type2') {
$imgObj.css('-webkit-mask', '-webkit-gradient(radial, '+iHalfHeight+' '+iHalfHeight+', '+ iRad +', '+iHalfHeight+' '+iHalfHeight+', '+ (iRad + 30) +', from(rgb(0, 0, 0)), color-stop(0.5, rgba(0, 0, 0, 0.2)), to(rgb(0, 0, 0)))');
}
// when radius is more than our width - stop loop
if (iRad > iWidth) {
window.clearInterval(iInt);
}
iRad+=2;
}, 10);
}, function(){});
});
Bookmarks