• iScroll框架的修改


    在使用过程中遇到了一些问题,通过修改iScroll框架得以解决,如下

    增加自定义滑动宽度

    iScroll框架默认滑动的宽度为当前获取对象的宽度,当在形如400px宽的对象里有4张图片,我们每次只希望滑动100px的宽度暨一张图片,做如下修改:

    1.在that.options里增加一个配置项getScrollW : “”,这里默认为空

    2.在refresh方法里找到that.wrapperW = that.wrapper.clientWidth;并修改为that.wrapperW = that.options.getScrollW ? that.options.getScrollW : that.wrapper.clientWidth;

    3:在refresh方法里找到that.scrollerW = m.round(that.scroller.offsetWidth * that.scale);并修改为that.scrollerW = m.round((that.options.getScrollW ? that.scroller.offsetWidth – that.wrapper.offsetWidth + that.options.getScrollW : that.scroller.offsetWidth) * that.scale);

    增加自定义滑动宽度在iScroll里的修改就完成了,自己在用的时候,在new iScroll里可以按照配置别的参数一样,配置getScrollW 属性,如果为空或没有配置,就默认滑动当前对象的宽度,如果设置了getScrollW:100px,则就每次滑动100px;

    增加解锁状态pullLock

    iScroll默认在加载完后,会阻止浏览器的默认行为,如左右滑动的时候,这个时候会阻止上下滑动,这样对很多文章内容页相对较长的页面显然不适用,修改如下

    1:在that.options里增加一个配置项pullLock: true,这里默认为true

    2:在_start方法里找到e.preventDefault();,并修改为if(!that.options.pullLock){e.preventDefault();}

    3:在_move方法里找到e.preventDefault();,并修改为if(that.options.pullLock){if(newY>=-10 && newY<=10){e.preventDefault();}}else{e.preventDefault();}

    增加解锁状态在iScroll里的修改也完成了,自己在new iScroll的时候,增加一个配置项pullLock,如果为true的话,就不会阻止浏览器的默认行为,如果为false的话,就会阻止浏览器的默认行为,这个可以自己根据需求制定。
    修改destroy方法

    iScroll在初始化的时候,对resize事件做了绑定操作that._bind(RESIZE_EV, window);,但是当在destroy销毁事件的时候,做的解绑that._unbind(RESIZE_EV);没有加window对象,不知道为什么,这个改成that._unbind(RESIZE_EV,window);就行了。

  • 相关阅读:
    block、inline、inline-block
    js 的复制和引用 (传值和传址)
    俄罗斯方块和作品集
    js 连续赋值。。理解不了,先占坑
    8.7 jquery-dom manipulation
    08.04 对象构造方法
    对象的基本操作
    08.03 js _oop
    08.02 对象
    The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
  • 原文地址:https://www.cnblogs.com/asqq/p/2833492.html
Copyright © 2020-2023  润新知