zoukankan      html  css  js  c++  java
  • ios 点击失效、闪屏问题解决方案

    一、点击失效

    描述:将点击事件(click)委派在document或者body上,且目标元素为默认不可点击的元素时(非<a>、 <button>而是<span>等),点击失效。

    实例代码:

    <body>
        <div class="page-content">
            <ol class="scence-hot">
                <li data-id="1-1" data-type="1" data-event="J_storeHotBtn"></li>    
            </ol>
        </div>
    </body>

    // 点击事件按钮
    $('body').on('click', '[data-event]', function(e) {
      var arr = $(this).data('event').match(/J_(w+)Btn/);
      var selector = arr[1];

      switch (selector) {
        case 'storeHot':
          $targetElem = $targetElem.parent('li').length ? $targetElem.parent('li') : $targetElem;
          var type = $targetElem.data('type');
          var id = $targetElem.data('id');
          switch (type) {
            case 1:
              self._createDialog('hot-store', '', id);
              break;
            case 2:
              self._createDialog('hot-hb', '', id);
              break;
            case 3:
              self._createDialog('hot-hb-simple', '', id);
              break;
          }

        break;

      }

    });

    解决办法有五种:

    1、取消事件委派,将事件直接绑定在目标元素本身上;

    2、将目标元素更换成默认可点击的元素,如<a>、<button>;

    3、将事件委派在非document或body上;

    4、将目标元素增加样式cursor:pointer;

    5、将click事件换成touch事件。

    方案3为最佳方案,其他三种的代价相对较大。方案1,不便于代码的管理、性能等;方案2,区块的点击无法实现(语义等方面考虑);方案4,影响展现,会改变原有的交互体验。方案3几乎没有以上几点缺点。

    二、点击闪屏

       ios下闪屏问题,由事件委派引发,解决方案如下:    

        1、去除事件委派;

        2、给委派的元素加上属性

          -webkit-tap-highlight-color: rgba(0,0,0,0);

          -webkit-user-select: none;

      方案2为最佳方案。

  • 相关阅读:
    Python单例模式中的4种方式
    Python list,tuple,dict,set高级变量常用方法
    python如何获取多个excel单元格的值
    两种方法实现python操作日志的封装
    numpy中函数shape的用法
    python中timer定时器常用的两种实现方法
    详解Python中argpasrse模块的基本使用
    在python中列表删除和多重循环退出
    Python的驻留机制(仅对数字,字母,下划线有效)
    python实现tail -f 功能
  • 原文地址:https://www.cnblogs.com/hity-tt/p/6423591.html
Copyright © 2011-2022 走看看