cubiq / iscroll

Smooth scrolling for the web
http://iscrolljs.com
MIT License
12.87k stars 3.8k forks source link

Change options dynamically #1036

Closed alvarotrigo closed 8 years ago

alvarotrigo commented 8 years ago

Is there a way to change iScroll options dynamically without having to destroy and initialize it again?

In my case I would like to set mouseWheel value depending on some events. I didn't see anything in the docs about it, but I might have missed it...

alvarotrigo commented 8 years ago

Any feedback on this?

alvarotrigo commented 8 years ago

I've been trying the following, but it seems the refresh it is not intended for this purpose?

$('button').click(function(){
    myScroll.options.mouseWheel = false;
     setTimeout(function () {
        myScroll.refresh();
    }, 0);
});

I got the idea from: https://groups.google.com/forum/#!topic/iscroll/LEvagkZqu_I

cubiq commented 8 years ago

yes this is perfectly legit. be careful though because some options are used at startup so it might not be possible to change them on the fly. I'd say you should be safe with 99% of them

alvarotrigo commented 8 years ago

But the example link provided shows it is not working in my case with the mouseWheel option ?

Is it possible in that case?

cubiq commented 8 years ago

I told ya :)

alvarotrigo commented 8 years ago

So... should I assume from that answer that this method doesn't work for the mouseWheel option?

Any workaround?

cubiq commented 8 years ago

unfortunately, yes... BUT it would be easy to disable wheel on the fly.

All you have to do is to remove (or add) the following events from the this.wrapper element: 'wheel', 'mousewheel', 'DOMMouseScroll'

cubiq commented 8 years ago

for reference https://github.com/cubiq/iscroll/blob/master/build/iscroll.js#L1094

alvarotrigo commented 8 years ago

Thanks for it, I'll take a look at it.

cubiq commented 8 years ago

very untested but should get you started

https://jsfiddle.net/511wmq3h/13/

alvarotrigo commented 8 years ago

Thanks! Should I assume it doesn't support IE 8?

The docs are not very clear about it:

Out of the box multi-platform support. From older Android devices to the latest iPhone, from Chrome to Internet Explorer.

But it seems in the code it is missing the attachEvent event for IE < 9:

//add
this.wrapper.attachEvent('onmousewheel', this);  //IE 6/7/8

//remove
 this.wrapper.detachEvent('onmousewheel', this); //IE 6/7/8
cubiq commented 8 years ago

IE8 is not supported, the latest commit adds some kind of IE8 compatibility @sculove can help you with that. IE8 should burn in hell!

alvarotrigo commented 8 years ago

Yeah, not such a big deal anyways. Just wondering.

eliteproxy7 commented 7 years ago

i am trying to remove snap once the scroll reaches the first snap so it can scroll normal after. I managed to set snap = false and refreshed but it throws this error which causes the animation to pause

Cannot read property 'length' of undefined

whats the best way to remove snap and bring it back in as needed or achieve what i am trying to do

leehoss commented 6 years ago

@eliteproxy7 try myScroll.options.snap = false; worked for me