闭包的一些应用

用于存储变量

/**
 * 监听下拉滚动事件
 */
function watchTouchScrollFn() {
  let scrollTopStart = 0;

  return function() {
    $('body').bind('touchstart', function() {
      scrollTopStart = $(window).scrollTop();
    });
    $('body').bind('touchend', function() {
      if ($(window).scrollTop() !== scrollTopStart) {
        // 打印下拉滚动日志
        // track.log({
        //   sub_type: 60,
        //   ua_type: uaType,
        //   tuia_id: tuiaId,
        //   ip: ip
        // });
      }
    });
  }
}
let watchTouchScroll = watchTouchScrollFn();

// 监听下拉滚动事件
watchTouchScroll();
posted @ 2017-11-30 10:08  暖风叔叔  阅读(199)  评论(0)    收藏  举报