Jan 15 / jQuery Custom Content Scroller mobile extension [updated 18/03]
Tags / Tips & Tricks, JavaScript, jQuery
View count: 3469
DISCUSS 32

Following a little discovery of my own and that being confirmed by the creator himself it turns out that jQuery custom content scroller by malihu is not functioning as intended if loaded using mobile browser. That clearly sounded like an issue since nowadays millions are browsing using mobile phones and tablets. And as resolutions on those devices are allowing websites to render in their normal state rather than the mobile, stripped off of all the goodies one, it was obvious something had to be done to enjoy such a great plugin in all environments. 

This time, as opposed to the previous enhancement to custom scroller that was published few month ago on this very same blog, I have written the plugin making the implementation much easier.

To start with, If you haven't set up the scroller yet, follow the tutorial from the original plugin site. Please note to be able to scroll in the mobile browsers you will be required to add up & down buttons [optional as full touch functionality has been added in the latest version].

The jQuery custom content scroller plugin and implementation tutorial can be found here:

http://manos.malihu.gr/jquery-custom-content-scroller

Now that you are done with it let's add the mobile functionality in these few easy steps:

1. Firstly download the script using the download box at the bottom of this post.

2. Add the script right after original custom scroller.

<script src="jscripts/customScrollBarMobile.js" type="text/javascript"></script>

3. Add the following extra right after you load custom scroller so it looks something like this:

$("#container_name").mCustomScrollbar(
"vertical",200,"easeOutCirc",1.05,"auto","yes","yes",10
);

if (jQuery.browser.mobile == true) {
$("#container_name").mCustomScrollbarMobile("vertical",200,5); 
}

Bear in mind the first bit of the above code is what you meant to have already before starting with the step 1.

What the script does is first of all a quick check on the type of browser you are using (big thanks for this goes to the detectmobilebrowsers.com). Then should the mobile browser be detected, a little mobile enhancement is being applied to allow users scrolling of the content using up & down buttons on their mobile devices. 

Please note it is a so called version 1 of the script, hence you will have to tap on the button to achieve scrolling. Holding down your finger will most likely cause execution of the browser's own built in functionality such as nearby text selection etc. Also script so far only works for the vertical scrolling.

After few requests I have updated this plug-in to so called version 1.1 which now includes two parameters - choise of scrolling direction (vertical/horizontal) and scrolling distance.

The latest update brings the full touch functionality. Now you can scroll the content div not only by using the extra buttons, but the touch gestures too. Plug-in supports up/down and left/right movements. 

Please note an extra variable has been added to the call of the plugin - the distance of scrolling when scrolling the main div using touch gestures. Therefore the call to the plugin now should contain three variables: direction, distance of scrolling when using buttons and distance of scrolling when using gestures.

Also, it is worth mentioning that scrolling using the dragger is not supported. As styling allows it to slim down significantly, in most cases it is hard to touch the right element in the first place. Therefore at this very time there are no plans in place for implementation of such functionality.

The script has been tested using few mobile browsers, such as Android for tablets, safari for iPhone and Symbian. Newest NokiaBrowser was not recognising scrolling gestures. However the fallback scrolling using buttons is working as it should.

If you discover the browser that fails to load the script, the suggestion would be to double check the first lines of code in the downloadable file to see whether your mobile browser is in the list. Also please share such discovery in the comment section below so the script could be updated.

Thanks to Ashlee for the discovery the script was not working on iPads. Problem is fixed now.

Also if you found this article helpful, you might be interested in adding further custom functionality to this jQuery content scroller. Take a look at our previous post:

Custom Functionality For jQuery Custom Scrollbar

So get coding and as usual, should you need any further information feel more than welcome to use the comments section below or contact us directly at blog@kartogram.co.uk

Regards,

SD

 

Big thanks goes to:
Mobile browser detection code for jQuery was borrowed from
http://detectmobilebrowsers.com/

Original jQuery Custom Content Scroller plugin. developed by Malihu: 

32 responses so far //

Jan 15 / malihu timestamp / 10:08 PM
Awesome! Thanks a ton for taking the time to further develop the plugin. I'll definitely add a link on the post :)
Jan 18 / joe timestamp / 5:14 PM
hi, thanks for the upgrade, do you know a way to make it work on horizontal scrolling?
Jan 18 / Simon Dau timestamp / 6:21 PM
@malihu u're welcome mate, glad to contribute
@joe, I'll try to extend it for horizontal scrolling as soon as I'll have some free time.
Jan 23 / Ashlee timestamp / 6:25 PM
The scroll doesn't work on my iPad. I wonder if need to be set to use your mobile js. Right now the iPad is detected as
No mobile browser detected.
Mozilla/5.0 (iPad; CPU OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3

Any ideas?
Jan 23 / Simon Dau timestamp / 7:00 PM
@Ashlee Hi, haven't got a chance to test it on iPad/iPhone as not owning any of those devices. When you open the script in the first part of it, where browser detection happens, pleae find a bit of code looking like 'ip(hone|od)' and try to add '|ipod|iphone' after it. It might help as I had similar glitch with android tablet when it was defined just as 'android.+mobile'. Respectively added 'android' after it and it worked. Let me know whether it works so I can update the code.
Jan 23 / Ashlee timestamp / 8:43 PM
I ended up adding this
http://jsfiddle.net/ashleigh8/Xdt76/

it works great now
Jan 23 / Simon Dau timestamp / 8:54 PM
@Ashlee Great! I have managed to test it with the iphone and it is working fine as it is. Furthermore, ipad was not even in the list so have added it and will try to test asap. Should it not work, I will utilise your tip.
Feb 06 / max timestamp / 8:24 AM
@joe, did you manage to make it work on horizontal scrolling?
@Simon Dau, great initiative! Is it hard to get this to work on horizontal scrolls?
Feb 06 / Simon Dau timestamp / 2:59 PM
@max Thanks! I have just updated the script. Now you can select which direction of scrolling you require as well as the scrolling distance.
Feb 06 / max timestamp / 3:23 PM
Dau dude! You are almost saving my week. I'm just trying this out on my iPad and I cant get the scrollbar or sliding to work. But the directional buttons work perfectly and will be enough for today, but are there anyone else that have managed this to fully work. Great Job Simon!
Feb 06 / Simon Dau timestamp / 3:39 PM
Thanks @max. This plug-in so far is intended just to give you that last resort when you load your page in mobile device and are not able to use malihu scroller. I'm currently working to add the functionality of scrolling while using the actual content or dragger rather than buttons. Will update when/if succeed.
Mar 02 / AL timestamp / 10:30 PM
HI, great solution. TKS
I have a problem.
With txt work great but with dinamic content in php no work.
Can you elp me?
tks
Mar 02 / Simon Dau timestamp / 11:22 PM
@AL If you are loading the dynamic content using AJAX then re-apply the plugin after loading is completed as it takes the height/width of the container as on of the initial parameters. Otherwise please review the code you got as most likely the mistake is somewhere there.
Mar 02 / AL timestamp / 11:30 PM
TKS for your answer but my problem is only with mobile in normal browser work great.
Mar 02 / AL timestamp / 11:32 PM
This is my code:


<script>

$(window).load(function() {
   mCustomScrollbars();
});

function mCustomScrollbars(){
   $("#mcs_container").mCustomScrollbar("vertical",400,"easeOutCirc",1.05,"auto","yes","yes",10);
}
   if (jQuery.browser.mobile == true) {
   $("#mcs_container").mCustomScrollbarMobile("vertical",400);
}
      
/* function to load new content dynamically */
function LoadNewContent(id,file){


   $("#"+id+" .customScrollBox .content").load(file,function(){
      mCustomScrollbars();
   });
}
</script>

<div id="mcs_container">
   
   <div class="customScrollBox">
      <div class="container">
      <div class="content">
      <?php $mytest = new nuggetz("tariffe");?>
   </div> <!--class content -->
</div> <!--class container -->

      <div class="dragger_container">
      <div class="dragger"></div> <!--class dragger -->
      </div> <!--class dragger_container -->
   </div> <!--class customScrollBox -->
<a href="#" class="scrollUpBtn"></a> <a href="#" class="scrollDownBtn"></a>
</div> <!--id mcs_container -->
Mar 02 / Simon Dau timestamp / 11:38 PM
@AL Where exactly is the problem? It doesn't load content in and the content div is empty? or everything loads well but it doesn't scroll while using the mobile browser? If so, which browser are you trying it on?
BTW your if (jQuery.browser.mobile == true) { bit is outside of the function brackets. That might be the problem.
Mar 02 / AL timestamp / 11:47 PM
Simon hi see the content but no the scroll line becouse when load the page i can see de scroll line but when finish the load page the scroll line disappears.
I used nokia 5700 express music with obera browser.
In the normal browser on Pc e mac work great.
Mar 02 / Simon Dau timestamp / 11:51 PM
Try to load it without mobile extension. If the same happens it is something to do with the original plugin. In this case try contacting malihu. The mobile extension does not affect how the content is loaded. It just disables the buttons and then re-assigns new functions to it so you are able to scroll on mobile browser.
Mar 03 / AL timestamp / 12:04 AM
I tryed whitout mobile extention but like problem.
Mar 19 / Nate timestamp / 6:22 PM
I am having some issues getting the this to work on my iPad, I have tried the suggestions above to no avail, the scrolling working fine on my desktop browsers. The site is located at: natehovinga.com/dev/smoes. Any help would be much appreciated. Thanks.
Mar 19 / Simon Dau timestamp / 9:50 PM
@Nate it doesn't work on Android tablet too. Not sure why though. Could be something to do with the dynamic loading of the content into the same div. Will prepare a demo page for this plugin as soon as I will find a free minute. Will try dynamic content loading too. In the meantime try adding the control buttons to see whether the plugin is getting applied in the first place.
Mar 19 / Simon Dau timestamp / 9:52 PM
@Nate mate, just realised you have referenced the mobile plugin wrong. all your javascript files are in the 'js' directory, not 'jscripts'.
Mar 20 / Nate timestamp / 1:21 PM
Thanks for the assistance, I have updated the js reference and also have added in the buttons, everything works fine on my PC, however it does not function on my iPad/phone. Everything is rendering proberly on the mobile devices but the scrolling doesnt work with either touch scrolling or by pressing the up and down buttons. Thanks.
Mar 20 / Simon Dau timestamp / 7:34 PM
@Nate I've done a copy of your site and tested it on android native/nokia belle native/opera for both mentioned and it works fine.
You can find it here: http://dev.kartogram.co.uk/index.html
BTW please re-download the plugin as a small amendment was made to it so it doesn't struggle on Android native browser. Though iOS browsers where not affected by it so even with your current code it should work. Hope the page will be of any help to you and will work as a good starting point.
Apr 21 / Ljube timestamp / 4:33 PM
Hello Simon Dau,

Thank you for your hard work on this plugin. If you have some time, please, could you tell me how to make the dragger drag content on mobile. I wont impleted this for the slider in this site: http://acm.test.wildsea.nl/ (slider is on the right side)
I tried many different ways, but I could not adjust your plugin to do this.

My knowledge of jQuery are not very strong and perhaps it proved insufficient.

Thank you very much and have a nice day,
Ljube
Apr 24 / Simon Dau timestamp / 1:30 PM
Hi Ljube. Thank you for your comment. An implementation of the touch control functionality for mobile devices can vary significantly from plug-in to plug-in. Therefore I am not able to advise you as of how exactly it should be implemented on your plug-in without having an in-depth analysis of the code.
Apr 28 / Ljube timestamp / 7:32 PM
Hi Simon,
thank you for replay.

I found some kind of solution. I used this: http://acm.test.wildsea.nl/wp-content/themes/acm/js/jquery.touch.js for make drag draggable in mobile (ios & android). The solution is not perfect, but work.

Kind regards,
Ljube
May 10 / pedroR timestamp / 12:42 PM
Hi.

I implemented the custom scrollbar from malihu. And now I was interessed in make some compatibility with mobile browsers for the scroll bar.

I tryed your code and for iPad it didn't work and in my mobile phone (android) it scroll down, just while I'm touchin the screen. If I stop touch the content automatically scroll too the top as you can test.

Any tips ???

Thanks all for the good work
May 10 / Simon Dau timestamp / 5:26 PM
@Pedror Thank you for your interest in this plug-in. Have you tried our demo page? Did it work for you? If so try adding an extra paragraph of text to see whether that solves it. And please let me know how it goes.
May 11 / Simon Dau timestamp / 5:49 PM
@Pedror I have looked up your code and you've done some good mess there. A copy of your page can be found here: http://dev.kartogram.co.uk/.
I've tested it on the android tablet and it works perfectly fine (although your original page didn't). Have a study on the source code of it to see what's changed and you'll be good to go. Cheers, Simon.
May 19 / Erin Freeman timestamp / 1:26 AM
Is there any way to speed up the gesture movement? i.e. at the moment the scroll follows my finger across the screen at the same rate, would like to be able to scroll it a bit quicker ideally if at all possible, I've tried increasing the step size but I suspect that's just for the buttons.

I found the 'tmbt' variable but adjusting that didn't seem to have much result, so I presumed this was something that was going to be worked into the script at some point but wasn't yet working?
May 19 / Erin Freeman timestamp / 1:31 AM
Ignore that last comment... totally overlooked some of the options! :)

Leave a Comment //

name
email
website
comment
Leave this field empty: