$.mobile.silentScroll does not work in worklight app

℡╲_俬逩灬. 提交于 2019-12-02 09:05:08

I don't think you can do this with jQuery Mobile's silentScroll, as it basically uses window.scrollTo, and this 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', '0s');"/>
                    </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>

0s means there will be no scroll effect; it will essentially 'jump' to the desired location.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!