jquery - 当我点击手机屏幕上的后退按钮时图像消失

标签 jquery css

我在网站上实现悬停效果时遇到问题。效果在桌面上运行良好。在手机上,图像都正常显示,当我点击它们时,它们会带我到正确的链接。但是当我在浏览器上按回键时,我看到的只是图像替代文本。有人可以建议吗?这是我目前拥有的代码。对于类似问题,我似乎无法在这里找到任何解决方案。谢谢

$(document).ready(function () {
$('.img1')
    .mouseover(function () {
    $(this).attr("src", "https://cdn.shopify.com/s/files/1/1297/5789/t/3/assets/Easy_Motion_-_Electric_Bicycles_Two.jpg?6314974642385151026");
})
    .mouseout(function () {
    $(this).attr("src", "https://cdn.shopify.com/s/files/1/1297/5789/t/3/assets/Easy_Motion_-Electric_Bikes.jpg?10135819641956685452");
});

<div class='desktop-4 tablet-full mobile-full'><a href='/home'><img src="https://cdn.shopify.com/s/files/1/1297/5789/t/3/assets/Easy_Motion_-Electric_Bikes.jpg?10135819641956685452" alt="electric bikes by easy motion" class="img1"/></a></div>

最佳答案

只需为移动设备禁用它(mouseenter ecc.. 不起作用)

$(document).ready(function() { 
    if(!isMobile) {
        // your code...
    }
});

检查这个问题:What is the best way to detect a mobile device in jQuery?用于检测移动设备或使用 Modernizr 检测是否启用了触摸

关于jquery - 当我点击手机屏幕上的后退按钮时图像消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40871791/

相关文章:

jquery - 使用 JQuery 更改 Facebook 元标记内容属性

javascript - 在页面加载事件中使用 Javascript 更改 CSS

css - 语义 UI 垂直对齐图标和菜单

jquery - 在通过 javascript 填充的表单选择上使用 jQuery-chosen

javascript - 网站需要自动调整页面上每个元素的大小,例如图像和字体

html - 伪元素上的 css 过渡不起作用

html - 如何使 HTML 文本框占满页面宽度

html - 如何在同一行重叠 bootstrap 3 中的列?

php - 防止不同用户同时进行多个投票

javascript - html 输入文件上传返回 null