jQuery脚本滚动在iDevices上不兼容

jQuery script rollover not compatible on iDevices

本文关键字:不兼容 iDevices 脚本 滚动 jQuery      更新时间:2023-09-26

我有一个jQuery脚本来管理图像的滚动。我的脚本在PC上运行良好,但不幸的是,这个脚本与iDevices(iPad、iPhone)不兼容。

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

你能帮我吗?

$(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");
    });
  });
});

试试这个:

$(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");
        });
    });
});

你仍然需要触摸(点击)手机上的图像,因为没有悬停。