zoukankan      html  css  js  c++  java
  • 模拟按钮hover效果

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4 <meta charset="utf-8">
     5 <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
     6 <meta content="yes" name="apple-mobile-web-app-capable">
     7 <meta content="black" name="apple-mobile-web-app-status-bar-style">
     8 <meta content="telephone=no" name="format-detection">
     9 <meta content="email=no" name="format-detection">
    10 <style type="text/css">
    11 a{-webkit-tap-highlight-color: rgba(0,0,0,0);}
    12 .btn-blue{display:block;height:42px;line-height:42px;text-align:center;border-radius:4px;font-size:18px;color:#FFFFFF;background-color: #4185F3;}
    13 .btn-blue:active{background-color: #357AE8;}
    14 </style>
    15 </head>
    16 <body>
    17 
    18 <div class="btn-blue">按钮</div>
    19 
    20 <script type="text/javascript">
    21 document.addEventListener("touchstart", function(){}, true)
    22 </script>
    23 </body>
    24 </html>

    兼容性ios5+、部分android 4+、winphone 8

    要做到全兼容的办法,可通过绑定ontouchstart和ontouchend来控制按钮的类名

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <style type="text/css">
    a{-webkit-tap-highlight-color: rgba(0,0,0,0);}
    .btn-blue{display:block;height:42px;line-height:42px;text-align:center;border-radius:4px;font-size:18px;color:#FFFFFF;background-color: #4185F3;}
    .btn-blue-on{background-color: #357AE8;}
    </style>
    </head>
    <body>
    
    <div class="btn-blue">按钮</div>
    
    <script type="text/javascript">
    var btnBlue = document.querySelector(".btn-blue");
    btnBlue.ontouchstart = function(){
        this.className = "btn-blue btn-blue-on"
    }
    btnBlue.ontouchend = function(){
        this.className = "btn-blue"
    }
    </script>
    </body>
    </html>
  • 相关阅读:
    在编码转错的情况下,如何恢复
    【娱乐】给你的电脑检查兼容性,并获取你的电脑上安装的软件
    发布一个纯PHP的中文关键字自动提取工具
    [转]程序员能力矩阵 Programmer Competency Matrix
    解决PHP数组内存耗用太多的问题
    哈希表之数学原理
    PHP高级编程之单线程实现并行抓取网页
    如何自动的检测字符串编码
    如何检测网络中断, 并自动重启网卡
    完全二叉树判断,简单而复杂
  • 原文地址:https://www.cnblogs.com/webgg/p/5341764.html
Copyright © 2011-2022 走看看