当页面向下滚动一半时,scrollTop无法正常工作

时间:2014-06-27 10:54:30

标签: javascript jquery html ios css

我正在为Iphone开发应用程序,但我遇到了问题。当侧面板打开时,我用scrollTop()导航到页面顶部。如果页面向下滚动,侧面板可以看到一点点它不会滚动到顶部,但是当我看不到面板时它将滚动到顶部。
这是我的HTML:

<div data-role="page" id="home" align="center">
    <div data-role="panel" id="popupPanel" data-position="left" ontouchmove="event.preventDefault()" data-display="reveal">
        <h3 id="userName2" class="blockText2"></h3>
        <ul data-role="listview" data-theme="b" style="margin-top:10px;">
            <a data-icon="false" data-role="button" data-shadow="false" data-corners="false" data-theme="b" id="seeYourProfile" href="#yourProfile" data-transition="slide" class="contentLink">Profile</a>
            <a data-icon='false' data-role="button" data-transition="slide" data-shadow="false" data-corners="false" data-theme="b" href="#about" class="contentLink">About</a>
            <a data-icon='false' data-role="button" data-transition="slide" data-shadow="false" data-corners="false" data-theme="b" href="#contacts" class="contentLink">My Contacts</a>
            <a data-icon='false' data-role="button" data-transition="slide" data-shadow="false" data-corners="false" data-theme="b" href="#teams" class="contentLink">My Teams</a>
            <a data-icon='false' data-role="button" data-transition="slide" data-shadow="false" data-corners="false" data-theme="b" onclick="sc.signOut();return false;" class="contentLink">Logout</a>
        </ul>
    </div>
    <div data-role="header" id="header" data-position="fixed" data-tap-toggle="false" style="z-index:99999;">
        <a href="#home" data-theme="none" data-role="none" id="btPopUpPanel" style="float:left;color:lightgrey;text-decoration:none;" data-direction="reverse" data-transition="slide"><i class="icon-reorder icon-2x"></i></a>
        <h1>News feed</h1>
        <a data-role="none" data-theme="none" id="btRefreshAllActivities" style="float:left;color:lightgrey;text-decoration:none;" data-transition="slide"><i class="icon-refresh icon-2x"></i></a>
    </div>

    <div data-role="content">
        <h3 id="noActivities">No activities found.</h3>
        <ul data-role="listview" data-theme="a" id="listActivities"></ul>
        <div id="submitBtn" style="margin-top:20px;">
            <button type="submit" data-shadow="false" data-corners="false" data-role="button" data-theme="b" id="btMoreActivity">More Activity</button>
        </div>
    </div>



这是我的JS:

$('#btPopUpPanel').on('vclick', function() {
    if ($.mobile.activePage.jqmData("panel") !== "open") {
        $("#popupPanel").panel("open");
        $("#popupPanel").scrollTop();
    } else {
        $("#popupPanel").panel("close");
    }
});



我也尝试了$("#home").scrollTop();$("#popupPanel").scrollTo(0,0);,但它没有用。有人有什么建议吗?

2 个答案:

答案 0 :(得分:0)

自己找到答案,而不是使用$("#popupPanel").scrollTop();我使用document.getElementById('popupPanel').scrollIntoView();

答案 1 :(得分:0)

即时滚动到顶部

 $(document).scrollTop(0);

动画滚动300毫秒

$('html, body').animate({
      scrollTop: 0
}, 300);