Firstly would like to thanks @prinzhorn for such an amazing and powerful library. My question: I have implemented a Skrollr parallax background to the header of my website but I would like to disable this feature when viewed on a mobile device, particularly iphones, etc. eg. (max-width: 767px).I was wondering what would be the best way to do this? And if the destroy() function was able to do this or I should be using another technique? Also, if destroy() is the answer, how could I implement this correctly? Many thanks and examples or demo's greatly appreciated.
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
You can also use userAgent detection - so smaller desktop resolutions still get the parallax effect:
In some cases you just disable the transitions:
The
.destroy()
method is the correct method to use; however, I would approach this differently than the accepted answer. Initializing the skrollr instance a second time to destroy it is unnecessary and performance can be improved using the.get()
method, like so:Skrollr never gets initialized a second time if it currently exists and is only destroyed if it exists. This avoids any bugs you may find by the brief moment between initializing and destroying (I speak from experience on this).
The destroy() method does do that. You can also avoid initializing skrollr on small windows to begin with, and/or destroy skrollr if the window gets resized to be small.
In this example, skrollr does not get re-enabled if the window gets resized to be large.
For me I wanted only some effects to be disabled on some mobile. I was using Bootstrap for responsiveness so some effects on desktop interfered when the columns collapsed on mobile.
My solution was to make a custom class on the effects I didn't want to work on mobile.
disable-mobile-skroll
and then remove the data attributes I was using before skrollr was being initialized.Skrollr has its own mobile check function