Search code examples
androidangularjsibm-mobilefirstscrollto

window.ScrollTo does not work with Worklight in Android


I'm developing an app using worklight and angular. I need to open a particular modal screen and the background screen, is rolled given element (by id). Using window.scrollTo command works perfectly in the emulator worklight, but when installing the application on the Android operating system has no effect. Any suggestions for another way to perform this action?


Solution

  • I explain why window.scrollTo cannot be used, and provide an alternative using iScroll as well as an example in the following question: $.mobile.silentScroll does not work in worklight app

    Here it is again, slightly edited for this question:


    window.scrollTo allows to scroll only within the current viewport (what you currently see on the screen).

    Instead I would recommend to use iScroll's various API methods: scrollTo, ScrollToElement or Snap, etc.

    I tested the below in Android and it worked.
    You'll of course need to adjust it to your application...

    common\js\main.js:

    var myScroll;
    
    function wlCommonInit(){
        myScroll = new IScroll('#wrapper');
    }
    

    common\index.html:

    <body style="display: none;">
            <div id="wrapper">
                <div data-role="page" id="page">
                    <div data-role="content" id="content" style="padding: 15px">                
                        <div id="firstDiv">
                            <input type="button" value="scroll to the other div" onclick="myScroll.scrollToElement('#secondDiv', '1s');"/>
                        </div>
                        <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
                        <div id="secondDiv">
                            hello
                        </div>
                    </div>
                </div>
            </div>
            ...
            ...
    </body>