Pergunta

I have a jQuery script to manage the roll-over of my images. My script works fine on PC but unfortunately this script isn't compatible with iDevices (iPad, iPhone).

image-normal.jpg <=> image-hover.jpg

Can you help me please ?

$(document).ready(function(){
  $(function () {
    $('img.rollover').hover(function () {
      $(this).css("cursor", "pointer");
      this.src = this.src.replace("-normal","-hover");
    }, function () {
      this.src = this.src.replace("-hover","-normal");
    });
  });
});
Foi útil?

Solução

Try this:

$(document).ready(function(){
    $(function () {
        $('img.rollover').on('mouseenter touchstart', function(){
            $(this).css("cursor", "pointer");
            this.src = this.src.replace("-normal","-hover");
        });

        $('img.rollover').on('mouseleave touchend', function(){
            this.src = this.src.replace("-hover","-normal");
        });
    });
});

You will still need to touch (click) the image on mobile as there is no hovering.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top