简体   繁体   English

编辑初始化时给定的iscroll4参数

[英]edit parameters of iscroll4 given at the time of initialisation

I am trying to use iscroll4 in my IOS app development with cordova 2.1.0. 我正在尝试在Cordova 2.1.0的IOS应用程序开发中使用iscroll4。

<script type="application/javascript" src="iscroll.js"></script>
<script type="text/javascript">
var myScroll;
function loaded() {
    setTimeout(function () {
        myScroll = new iScroll('wrapper');
    }, 100);
}
window.addEventListener('load', loaded, false);
</script>

If i want to edit the parameters like vScroll , vScrollBar,fixedScrollbar etc. dynamically ie. 如果我想编辑参数,如vScroll,vScrollBar,fixedScrollbar等,即动态。 after the initialisation of iscroll(myScroll = new iScroll('wrapper');), how can i do it in javascript. 初始化iscroll(myScroll = new iScroll('wrapper');)之后,如何在javascript中进行操作。 Thanks in advance. 提前致谢。

I wouldn't try to look for an 'works in every situation'-solution. 我不会尝试寻找“在任何情况下都可行”的解决方案。

I would: 我会:

  1. Sum up the particular options you would want to modify. 总结您要修改的特定选项。
  2. See which of these options matter during initialitation 查看初始化期间这些选项中的哪个重要
  3. programmatically (manually) change these options 以编程方式(手动)更改这些选项
  4. options that only matter at runtime (ie are read when an event occurs), I'd simply try to modify the myScroller.options object. 仅在运行时才有意义的选项(即在事件发生时读取),我只是尝试修改myScroller.options对象。

For example, you can set these options: 例如,您可以设置以下选项:

myScroller = new iScroll( el, { x:20, y:30, onRefresh: function(){ alert(11); } } );

Would you want to modify these 3 (or more..), considering my steps you'd do: 考虑到我的步骤,您是否要修改这3个(或更多)?

  1. x, y, scrollbarClass x,y,scrollbarClass

  2. in the initialization we see that x & y are used (line 120): 在初始化中,我们看到使用了x和y(第120行):

    // Set starting position that.x = that.options.x; //设置起始位置that.x = that.options.x; that.y = that.options.y; that.y = that.options.y;

That means that these options influences more than just runtime stuff, during initialization it modifies that.x en that.y (even tho pretty simple so far). 这意味着这些选项不仅影响运行时的内容,而且在初始化期间还会修改that.x和that.y(到目前为止,甚至还很简单)。

3. 3。

myScroller.x = newX;
myScroller.options.x = newX;
myScroller.y = newY; 
myScroller.options.y = newY;
// Also depeneds on x & y, but only do this if you actually useTransform and care about this!

/*
 * obtain required variables..
 */
var appVersion = navigator.appVersion,
    vendor = (/webkit/i).test(appVersion) ? 'webkit' :
        (/firefox/i).test(navigator.userAgent) ? 'Moz' :
        'opera' in window ? 'O' : '',

has3d = 'WebKitCSSMatrix' in window && 'm11' in new WebKitCSSMatrix(),

trnOpen = 'translate' + (has3d ? '3d(' : '('),
    trnClose = has3d ? ',0)' : ')';

// Code that actually matters, and where we use above variables
if (that.options.useTransform) that.scroller.style[vendor + 'Transform'] = trnOpen + that.newX + 'px,' + that.newY + 'px' + trnClose;
        else that.scroller.style.cssText += ';position:absolute;top:' + that.newY + 'px;left:' + that.newX + 'px';

4. 4。

myScroller.options.onRefresh = function() { alert(33); }

Maybe you can even do all these things in the options.onDestroy property ;) 也许您甚至可以在o​​ptions.onDestroy属性中完成所有这些操作;)

Update: I also noticed the destroy function, and might come in convenient if you do want to 'totally clear' the scroller. 更新:我也注意到了destroy功能,如果您想“完全清除”滚动条,它可能会很方便。 But I didn't see code that would remove the physically created scrollbar, but I'm not sure. 但是我没有看到能删除实际创建的滚动条的代码,但是我不确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM