MyBB Community Forums

Full Version: [Tutorial] Pull to Refresh on Mobile
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Sites like Twitter let you pull the page down and release to refresh the page in mobile view. An example of this can be seen in the screen shot below
[Image: uNdGuZ6.gif]


Step 1.
  • Download the pulltorefresh.min.js file attached to this thread
  • upload the pulltorefresh.min.js file to your /jscripts folder
Step 2.
  • Open AdminCP > Template & Style > Templates in Sidebar > Your Theme's Templates > header
  • Add the following code to the very top of the template (Line 1)
<div id="pulltorefresh"></div>
<script src="{$mybb->asset_url}/jscripts/pulltorefresh.min.js"></script>
<script>
PullToRefresh.init({
  mainElement: '#pulltorefresh', // above which element?
  onRefresh: function (done) {
    setTimeout(function () {
      done(); // end pull to refresh
document.location.reload(true);
    }, 1500);
  }
});
</script>
* If you have a fixed header (A header that follows you as you scroll) place the code below the header element. If you want the Pull To Refresh message to appear below your header, place the code below the header element.


And that's it. You're done. Open your site on your phone and test it out.

Demo Link (Mobile Only): https://www.rantcentralforums.com



Credit to BoxFactura for script
Cool tutorial, certainly a feature I'll consider implementing in my new forum theme once MyBB 1.9 is released.

Thanks for sharing.
(2019-01-31, 01:00 PM)avensis Wrote: [ -> ]Hi, I find this feature great, thanks for sharing this tutorial

(2019-01-31, 01:31 PM)kawaii Wrote: [ -> ]Cool tutorial, certainly a feature I'll consider implementing in my new forum theme once MyBB 1.9 is released.

Thanks for sharing.

No problem guys Smile
Thank you!
(2019-02-03, 12:21 PM)Eldenroot Wrote: [ -> ]Thank you!

No problem buddy.
Thanks a lot!
I like how it doesn't work within a PC (I used one before that did, it was kinda annoying).
(2019-02-06, 11:39 PM)Omar G. Wrote: [ -> ]I like how it doesn't work within a PC (I used one before that did, it was kinda annoying).

It isn't supposed to work on a PC because PCs are not classified as 'mobile' devices.
Unless it is a touch screen laptop I presume. But yes, sure, a touch screen laptop is neither a "PC". Unless you dock it to your desktop tho.
Very nice share, Sharee Wink
Javascript is beautiful.
Pages: 1 2