V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
shuperjolly
V2EX  ›  JavaScript

请问这个事件是怎么挂监听上去的阿

  •  
  •   shuperjolly · 2019-03-28 03:01:34 +08:00 · 2653 次点击
    这是一个创建于 1827 天前的主题,其中的信息可能已经有所发展或是发生改变。
    https://weui.io/

    首页菜单点击的风琴折叠动作

    我看 example.js 里创见了 TouchEvent 事件,然后在菜单的 div 中有 touchstart 和 touchend 事件监听,但是这个事件监听是用什么方法挂载这个 div 上的阿
    3 条回复    2019-03-28 15:29:32 +08:00
    shuperjolly
        1
    shuperjolly  
    OP
       2019-03-28 09:49:55 +08:00
    应该是这个函数
    function fastClick(){
    var supportTouch = function(){
    try {
    document.createEvent("TouchEvent");
    return true;
    } catch (e) {
    return false;
    }
    }();
    var _old$On = $.fn.on;

    $.fn.on = function(){
    if(/click/.test(arguments[0]) && typeof arguments[1] == 'function' && supportTouch){
    var touchStartY, callback = arguments[1];
    _old$On.apply(this, ['touchstart', function(e){
    touchStartY = e.changedTouches[0].clientY;
    }]);
    _old$On.apply(this, ['touchend', function(e){
    if (Math.abs(e.changedTouches[0].clientY - touchStartY) > 10) return;

    e.preventDefault();
    callback.apply(this, [e]);
    }]);
    }else{
    _old$On.apply(this, arguments);
    }
    return this;
    };
    }


    $.fn.on 这个是监听添加,但是这里面这个函数有老鸟帮忙说说什么逻辑吗
    lukaz
        2
    lukaz  
       2019-03-28 13:46:13 +08:00   ❤️ 1
    页面 js,$('.js_category').on('click', function(){ ... })
    shuperjolly
        3
    shuperjolly  
    OP
       2019-03-28 15:29:32 +08:00
    @lukaz 为什么它在页面 js 的这个标签里面加 class="home js_show",有什么作用啊
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3189 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 12:27 · PVG 20:27 · LAX 05:27 · JFK 08:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.