I try to write a jQuery code to manage my images buttons.
I would like to create buttons with this behaviours : http://jsfiddle.net/Xroad/fhL7w/17/
But the difference is that they are images buttons. I have several. So I would like to manage with their file names "-normal", "-hover".
My images buttons don't behave as I would : http://jsfiddle.net/Xroad/z562Y/ how can I fix it ?
I wrote this :
<img id="btn-clients" class="btn toggleImg rollover" src="http://pepitodanger.free.fr/forms/images/clients-normal.png" alt="">
function toggleImg() {
var file = $(this).attr('src');
var src = (file.indexOf('-hover') == -1) ? file.replace("-normal", "-hover") : file.replace("-hover", "-normal");
$(this).attr("src", src);
}
$('.toggleImg').hammer().on(Modernizr.touch ? 'tap' : 'click', toggleImg);
$('img.rollover').on('mouseenter', function () {
this.src = this.src.replace("-normal", "-hover");
});
$('img.rollover').on('mouseleave', function () {
this.src = this.src.replace("-hover", "-normal");
});
CSS.