web开发过程中,移动端按钮交互效果,点击按钮变色

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript">
        document.body.addEventListener('touchstart', function () {});
    </script>
    <style>
    .btn{
        font-size: 1.5em;
        line-height: 2em;
        text-align: center;
        color: #fff;
        background: #ce4f54;
        width: 200px;
    }
    .btn:hover,
    .btn:active,
    .btn:focus{
        background: #043d5d;
    }
    </style>
    <title>无标题文档</title>
</head>

<body>
    <div class="btn">测试Test</div>
</body>

</html>

  如果不绑定事件,在pc和安卓上可以实现

  绑定事件为了在ios中生效;

 

使用css3属性实现缓交互

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <style>
    .btn{
        font-size: 1.5em;
        line-height: 2em;
        text-align: center;
        color: #fff;
        background: #ce4f54;
        width: 200px;
        transition: 0.5s all;
        -webkit-transition: 0.5s all;
        -o-transition: 0.5s all;
        -moz-transition: 0.5s all;
        -ms-transition: 0.5s all;
    }
    .btn:hover,
    .btn:active{
        background: #043d5d;
    }
    </style>
    <title>无标题文档</title>
</head>

<body>
    <div class="btn">测试Test</div>
</body>

</html>

  3、通过js操作class

这个已经很多人写了,就不用写例子了

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
  • 2021-05-16
  • 2023-02-10
相关资源
相似解决方案