推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
shuperjolly

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

  •  
  •   shuperjolly · Mar 28, 2019 · 3202 views
    This topic created in 2628 days ago, the information mentioned may be changed or developed.
    https://weui.io/

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

    我看 example.js 里创见了 TouchEvent 事件,然后在菜单的 div 中有 touchstart 和 touchend 事件监听,但是这个事件监听是用什么方法挂载这个 div 上的阿
    3 replies    2019-03-28 15:29:32 +08:00
    shuperjolly
        1
    shuperjolly  
    OP
       Mar 28, 2019
    应该是这个函数
    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  
       Mar 28, 2019   ❤️ 1
    页面 js,$('.js_category').on('click', function(){ ... })
    shuperjolly
        3
    shuperjolly  
    OP
       Mar 28, 2019
    @lukaz 为什么它在页面 js 的这个标签里面加 class="home js_show",有什么作用啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2687 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:11 · PVG 19:11 · LAX 04:11 · JFK 07:11
    ♥ Do have faith in what you're doing.