zoukankan      html  css  js  c++  java
  • JQuery Mobile iscroll插件使用教程及注意事项

    中文文档:http://www.360doc.com/content/14/0724/11/16276861_396699901.shtml

    问题:使用了iscroll之后,你会发现点击输入框时不灵敏,经常无法聚焦;页面文字也无法选择和复制。这是由于iscroll要监听鼠标事件和触摸事件来进行滚动,所以禁止了浏览器的默认行为 ,包含在wrapper中的input、Seclect控件无法选择或点击

    解决办法:
    在创建Scorll时,定义以下方法

    onBeforeScrollStart: function (e) { 
    var target = e.target; 
    while (target.nodeType != 1) target = target.parentNode; 
    if (target.tagName != ‘SELECT’ && target.tagName != ‘INPUT’ && target.tagName != ‘TEXTAREA’) 
    e.preventDefault(); 
    }, 

    完整代码:

    /**
     * 初始化iScroll控件
     */
    function loaded() {
        pullUpEl = document.getElementById('pullUp');
        pullUpOffset = pullUpEl.offsetHeight;
        myScroll = new iScroll('wrapper', {
            useTransition: false, /* 防止更新时闪动 */
            topOffset: pullDownOffset,
            onRefresh: function () {
                if (pullUpEl.className.match('loading')) {
                    pullUpEl.className = 'tips';
                    pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
                }
            },
            onScrollMove: function () {
                if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) {
                    pullUpEl.className = 'flip tips';
                    pullUpEl.querySelector('.pullUpLabel').innerHTML = '松手开始更新...';
                    this.maxScrollY = this.maxScrollY;
                } else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match('flip')) {
                    pullUpEl.className = 'tips';
                    pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
                    this.maxScrollY = pullUpOffset;
                }
            },
            onScrollEnd: function () {
                if (pullUpEl.className.match('flip')) {
                    pullUpEl.className = 'loading tips';
                    pullUpEl.querySelector('.pullUpLabel').innerHTML = '加载中...';                
                    pullUpAction();    // Execute custom function (ajax call?)
                }
            },
            onBeforeScrollStart: function (e) {
                var target = e.target;
                while (target.nodeType != 1) target = target.parentNode;
                if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA')
                e.preventDefault();
            }
        });
        
        setTimeout(function () { document.getElementById('wrapper').style.left = '0'; }, 500);
    }
    
    document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
    document.addEventListener('DOMContentLoaded', loaded, false); //初始化绑定iScroll控件 
    点点滴滴,终汇一海
  • 相关阅读:
    前端十万个为什么(之一):我们为什么需要npm?
    初识模块化开发工具:
    javascript 中的 let 作用域
    把汉字转换为html实体编码
    【小程序】开发过程问题整理
    【入门】正则表达式
    【CSS】面试知识整理
    【入门】Gulp 简单使用
    【入门】WebSocket 示例
    【JQ】$.ajax() 参数
  • 原文地址:https://www.cnblogs.com/forever-cjs/p/5133190.html
Copyright © 2011-2022 走看看