gpt4 book ai didi

jquery - 更改触摸时链接的背景颜色

转载 作者:行者123 更新时间:2023-12-03 23:01:28 24 4
gpt4 key购买 nike

我试图在用户触摸/点击移动设备时更改链接的背景颜色,尽管以下代码有效,但有时链接仍保持黑色并且在释放时不会变回白色,是吗?更好的编码方式?

$('#test').bind('touchstart', function() {
$(this).css('background-color', 'black');
});

$('#test').bind('touchend', function() {
$(this).css('background-color', 'white');
});​

谢谢!

最佳答案

这可以在没有 jQuery 的 CSS 中完成:

a:active
{
background-color: black;
}

有关与 Android 原生浏览器的兼容性的注意事项

出于某种原因,上面的代码无法在 Android 的原生浏览器(也许还有其他一些浏览器)中运行。。但是,一旦添加 ontouchstart="" ,它就会起作用。 <body> 的参数像这样的标签:

<body ontouchstart="">

此外,Android Stock 浏览器默认会突出显示链接(在我的手机上为蓝色背景)。要禁用此功能,请键入:

a
{
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
}

参见thisthis了解更多详情。

Jsfiddle here

关于jquery - 更改触摸时链接的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16871000/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com