zoukankan      html  css  js  c++  java
  • 移动端模拟hover

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <title>移动端模拟hover</title>
    <style>
    html {
    font-size: 100px;
    }

    * {
    font-size: .16rem;
    }
    .content {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    overflow: auto;
    z-index: 10;
    background-color: #fff;
    -webkit-overflow-scrolling: touch;
    }
    .items {
    margin: 0;
    padding: 0;
    list-style: none;
    }
    .items li {
    box-sizing: border-box;
    line-height: .40rem;
    text-indent: 1em;
    border-bottom: 1px solid #e3e3e3;
    }

    .items li.active {
    background-color: #e3e3e3;
    }
    </style>
    </head>
    <body>
    <div class="content">
    <ul class="items">
    <li class="action-btn">item1</li>
    <li class="action-btn">item2</li>
    <li class="action-btn">item3</li>
    <li class="action-btn">item4</li>
    <li class="action-btn">item5</li>
    </ul>
    </div>

    <script src="http://dn.yunzhenshi.com/js/jquery-1.8.3.min.js"></script>
    <script>
    $(function () {
    //自定义tap
    $(document).on("touchstart", function (e) {
    if (!$(e.target).hasClass("disable")) $(e.target).data("isMoved", 0);
    });
    $(document).on("touchmove", function (e) {
    if (!$(e.target).hasClass("disable")) $(e.target).data("isMoved", 1);
    });
    $(document).on("touchend", function (e) {
    if (!$(e.target).hasClass("disable") && $(e.target).data("isMoved") == 0) $(e.target).trigger("tap");
    });

    //按钮点击效果
    $(document).on("touchstart", ".action-btn:not(.disable)", function (e) {
    var $this = $(this);
    var flag = true;
    //遍历子类
    $this.find("*").each(function () {
    //查看有没有子类触发过active动作
    if ($(this).hasClass("active")) flag = false;
    });
    //如果子类已经触发了active动作,父类则取消active触发操作
    if (flag) $this.addClass("active");

    });
    $(document).on("touchmove", ".action-btn:not(.disable)", function (e) {
    if ($(this).hasClass("active")) $(this).removeClass("active");
    });
    $(document).on("touchend", ".action-btn:not(.disable)", function (e) {
    if ($(this).hasClass("active")) $(this).removeClass("active");
    });

    });
    </script>
    </body>
    </html>

  • 相关阅读:
    css:chorm调试工具(修改样式、重置缩放比例、错误提示、语法快速生成)
    多线程:线程不安全案例(买票、银行取钱、集合)
    css:选择器(标签、类、ID、通配符)
    多线程:(优先级、守护线程)
    多线程(线程的状态、终止、休眠、礼让、合并)
    html:标签(标题、段落、换行、文本格式化、图像)
    多线程:多线程的应用(网图下载、模拟售票、龟兔赛跑)
    Struts2
    框架、MVC、MVC框架
    html5、css3、BootStrap
  • 原文地址:https://www.cnblogs.com/chengyunshen/p/7852731.html
Copyright © 2011-2022 走看看