css的active事件在手机端不生效的解决方法

请添加图片描述
需求:需求就是实现点击图中的 “抽奖” 按钮,实现一个按钮Q弹的放大缩小动画

上面是实现的效果,pc端,点击触发 :active

问题:但是这种方式在模拟器上可以,真机H5一调试就没生效了,下面是简单的demo代码

img{
	width:100px;
	height:100px;
	background:red;
}
img:active {
  animation: shake 1s infinite;
  animation-iteration-count: 1;
}

@keyframes shake {
  0% {
    transform: scale(0.98);
    opacity: 0.9;
  }

  50% {
    transform: scale(1);
    opacity: 0.7;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

解决方案:在页面body添加一个 ontouchstart=""

没错,就是这么简单

<body ontouchstart="">
    ...
</body>

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-23 08:46:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-23 08:46:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-23 08:46:01       87 阅读
  4. Python语言-面向对象

    2024-03-23 08:46:01       96 阅读

热门阅读

  1. 复习Day1

    2024-03-23 08:46:01       37 阅读
  2. HBase Shell的应用案例

    2024-03-23 08:46:01       31 阅读
  3. 【B树 B+树——数据结构】

    2024-03-23 08:46:01       46 阅读
  4. Git一点通

    2024-03-23 08:46:01       42 阅读
  5. Spring-ioc-纯xml配置

    2024-03-23 08:46:01       47 阅读