facebook

Tutorial: How to Scroll HTML Widget Content (Updated 28 Mar)

  1. MobiOne Archive
  2.  > 
  3. Examples, HOW-TOs
Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #337081 Reply

    support-michael
    Keymaster

    updated 28 March 2013, see below
    Tutorial: How to Scroll an HTML Widget

    Introduction
    The HTML Widget is relatively new and still evolving. As such, it does not “yet” provide a scroller mechnanism for its content. This discussion assumes you are familiar with the Panel widget and the HTML widget.

    Technique-1: Wrap HTML Widget in a Scrolling Panel
    1) The simplest approach for scrolling an html widget content is to embed the widget in a scrolling Panel with auto-resize set to fully fill the panel as it changes size, e.g., rotate the device.

    2) Select the panel and in the Properties enable the scrollbar and set the vertical height to the maximum size that you expect for html widget’s content.

    Limitations:
    1) The max height of a HTML Widget is 1000 px
    2) If you set the containing panel’s content height to be too tall or too short the UX can be feel awkward. This technique is even more limited if you need to dynamically load or update the html widget’s content at runtime.
    See attachment tech1-screen1-and-2.png

    Technique-2: Programmatically attach an iScroll(er) to an HTML Widget’s content
    A more natural approach is for the html widget’s contents to be scrolled directly rather than scrolling the entire html widget as in technique-1 above.

    The MobiOne Panel widget uses the iScroll4 javascript component to implement its vertical scroller. Thus, you can use an iScroll component for your own purposes. In this technique we wrap your custom html widget’s custom content in an iScroll.

    
    <div id="wrapper" style="width:100;height:100"> <!-- add a percent sign to both 100 values - -->
       <div id="scroller">                                       <!-- not shown due to portal's hatred for percent chars --> 
       <!-- custom content goes here -->
       </div>
    </div>
    
    <script type="text/javascript">
    $(document).ready(function() {
        // Fill HTML content
        for (var i=0; i<1000; ++i) {
            $("#scroller").append("<div>" + i + "</div>");
        }
    
        //create a vertical scroller with bounce effect
        var myScroll = new iScroll('wrapper', {        
            vScroll : true,
            vScrollbar: true,
            hScroll : false,
            hScrollbar: false,
            bounce: true,
        });
    });
    </script>
    

    If you dynamically update the html widget’s content you will need to call the javascript refresh() function on the scroller. See iScroller4 developer notes.

    See attachment tech2-screen1-and-2.png

    <Update – added Multipage example here>
    Technique-2A For HTML widget on a Multipage Widget
    If you plan to use an HTML widget with a custom scroller embedded on a multipage widget there is an additional configuration step. Begin as described in Technique-2 but add the add the HTML widget on page of a multipage widget instead of a panel widget. Use the same custom HTML code. Then add the following line of code as an On Page Change > Run as JavaScript action of the multipage widget. When the multipage widget is initialized the code will be executed to refresh() the iScroll component of the HTML widget. Prior to this the HTML widget is not fully initialized and its content’s size is unknown. The refresh() instructs the iScroller to recompute its size based on the “now” initialized HTML widget’s content.

    
      //call refresh() on the iScroll component attached to the <div id="scroller"> that is created in the HTML widget's code. 
      $("#scroller")[0].myScroll.refresh();
    

    See attachment tech2-multipagewidget-screen1a.png

    Conclusion
    We are planning to upgrade the HTML widget with a scroller properties and a small api in the near future.

    Download examples:
    See attachment ScrollHTMLWidget-Technique1.mobi See attachment ScrollHTMLWidget-Technique2.mobi See attachment ScrollHTMLWidget-Technique2-multipage.mobi

    Special thanks to Vadim Ridosh for his assistance in Technique-2 example and overall guidance.

    Attachments:
    You must be logged in to view attached files.
    #337118 Reply

    jim
    Member

    Very good examples. Much appreciated. Especially Technique2
    Jim

    #337135 Reply

    Brandon
    Member

    I am trying to get sample 2 working on my RSS feed, can you confirm this is NOT working in a multipage widget? I have it in a multipage and it is adding the content, but not the scroll bars. If I have the same html widget above the multipage, not in it, it seems to work.

    #337138 Reply

    support-michael
    Keymaster

    Update:
    I developed a small example below using a multipage widget.

    The dev team is evaluating how to incorporate a scrolling mechanism in the html widget but there is no way to make it bulletproof atm as a user’s html can totally muck up the scroller and the entire app as in some cases we have investigated.

    Here is an example of technique-2 using a multipage widget with html widget embedded on page-1.
    See attachment ScrollHTMLWidget-Technique2-multipage.mobi

    Attachments:
    You must be logged in to view attached files.
    #337148 Reply

    Brandon
    Member

    Works fine except if you try to copy the Html widget to page2…may be one of the rendering bugs like the map was doing?

    #337173 Reply

    support-michael
    Keymaster

    >Works fine except if you try to copy the Html widget to page2…may be one of the rendering bugs like the map was doing?

    Will post an improvement later today that addresses an initialization timing issue with the Multipage widget.

    Completed – See update today

    #337232 Reply

    Brandon
    Member

    Wayne,

    Thanks, I got it working!

    #337333 Reply

    support-michael
    Keymaster

    @Miguel

    Let’s back up and let me qualify that I fast tracked this tutorial to help out – specifically after your endless whining and angry rants via email. Then when I post something you tell me this fails and I’m lazy and this and that sucks. Try learning from others such as brandon who provide constructive feedback that I was able to act on. Please post an example so I can understand exactly what you are up to. I’ll see what I can do once I have a better understanding of your very specific problem.

    #337336 Reply

    Brandon
    Member

    Also, I have this coding running in my MobiOne CheatSheet and the textboxes are working fine and it is not on the main page and it is with a multipage widget (all the problems I was having have been fixed). Although I must quality this is not running as a native app so I do not know if that would change anything.

    #343422 Reply

    jailbird
    Member

    How I create scroll panel in JavaScript in custom.js ??

    #343853 Reply

    j.binkhadim
    Member

    thanks for the tutorial … but i am trying to scroll an < iframe > in the HTML widget … is it possible to so >> ??

    #345017 Reply

    davidg
    Member

    Hi Guys,

    I am trying to the iscroll to an html widget which displays an rss feed generated by a plugin.

    So far iscroll does not detect the content that is being loaded into it from the plugin js library called “feedget”. If I put other things in the html widget the scroll bars are enabled, just not the RSS feed content.

    Here is my code:

    <div id="wrapper" style="width:100(percent);height:100(percent)"> // I used the real percent sign, just changed for the post
       <div id="scroller">
             <ul id="feeddiv1">
                   <div data-role="page" data-theme="a" id="feeddiv1">
                   <div class="feeddiv1" style="overflow:auto;" data-role="content"></div>
            </ul>
        </div>
    </div>
    
    <script type="text/javascript">
    
    var myScroll;
    function loaded() {
        setTimeout(function () {
                var myScroll = new iScroll('wrapper', {        
            hScroll : false,
            vScroll : true,
            hScrollbar: false,
            vScrollbar: true,
            bounce: false,
        });
        
        // Save myScroll to allow multipage events to refresh it.
        $("#scroller")[0].myScroll = myScroll;
        }, 300);
    }
    window.addEventListener('load', loaded, false);
    
    $(document).ready(function() {
                
                $('.feeddiv1').feedget(
                    {
                        feed: 'http://feeds.feedburner.com/blogspot/NSYcE',
                        showHeader: false,
                        direction: 'vertical',
                        entries: 100,
                        images: false,
                        buttons: false,
                        facebook: false,
                        reverse: false,
                        fulltext: true,
                        loadingImg: 'loading.gif'
                    });
    
            });
    
    </script>
    

    Any pointers would be appreciated, thanks
    PS I’m html neewbie

    #345018 Reply

    Brandon
    Member

    My guess is that the feed is not being generated before the myscroll. Try adding a myScroll.refresh() after the feed is generated.

    #345019 Reply

    davidg
    Member

    @ CincyPlanet

    Thanks for the reply.

    Yeah, I had tried that before but I was getting an error in chrome debug: “Uncaught TypeError: Cannot call method ‘refresh’ of undefined”

    added the refresh as shown below:

    $(document).ready(function() {

    $(‘.yourdiv1’).feedget(
    {
    feed: ‘http://feeds.feedburner.com/blogspot/NSYcE&#8217;,
    showHeader: false,
    direction: ‘vertical’,
    entries: 100,
    images: false,
    buttons: false,
    facebook: false,
    reverse: false,
    fulltext: true,
    loadingImg: ‘loading.gif’
    });
    myScroll.refresh()
    });

    #345056 Reply

    Brandon
    Member

    function loaded() {
    setTimeout(function () {
    var myScroll = new iScroll(‘wrapper’, {
    hScroll : false,
    vScroll : true,
    hScrollbar: false,
    vScrollbar: true,
    bounce: false,
    });

    // Save myScroll to allow multipage events to refresh it.
    $(“#scroller”)[0].myScroll = myScroll;
    }, 300);
    }

    The line above : var myScroll = new iScroll(‘wrapper’, {

    Try taking out the var, I believe this will rescope the myScroll to the function only, instead of globally. Since you already declared it above the function.

Viewing 15 posts - 1 through 15 (of 23 total)
Reply To: Tutorial: How to Scroll HTML Widget Content (Updated 28 Mar)

You must be logged in to post in the forum log in