$.scrollTo doesn't work with position:fixed;

徘徊边缘 提交于 2019-12-25 02:53:33

问题


I have a jqm page with a panel. And I want the panel to scroll to a certain position. Using the $scrollTo plugin works, but it scrolls both the panel and the page itself.

$('#myPanel').on('panelopen',PanelOpen)
function PanelOpen(myEvent, myUI ) {
    $.scrollTo('#ID498',1000)
}

Here's my example showing it scroll the panel (hooray), and the page (boo).

Now, from this SO thread, I was able to make the panel scrollable:

#myPanel .ui-panel.ui-panel-open {
    position:fixed;
}
#myPanel .ui-panel-inner {
    position: absolute;
    top: 1px;
    left: 0;
    right: 0;
    bottom: 0px;
    overflow: scroll;
    -webkit-overflow-scrolling: touch;
}

But now the $.scrollTo plugin doesn't work. Here's my second example, this time with the panel scrollable, but I can no longer position it using JavaScript.


回答1:


I think you just need to call the scrollTo() on the inner panel div which is actually set to overflow and it will work:

function PanelOpen(myEvent, myUI ) {
    $("#myPanel .ui-panel-inner").scrollTo('#ID498',1000)
}

Here is a working DEMO



来源:https://stackoverflow.com/questions/23504288/scrollto-doesnt-work-with-positionfixed

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