0

用户向下滚动到页面底部后,导航回页面顶部不起作用。

页脚

<div data-role="footer" data-theme="b">
    <div class="ui-bar">
        <a href="" data-role="button" data-icon="arrow-u" data-theme="d" style="float:right;" class="returnTopAction">Return top</a>
    </div>
</div>

jQuery 参考

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>

更新: 我的完整 HTML 代码

<html>

    <head>
        <title>SQ/TR</title>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
        <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
    </head>

    <body>
        <div data-role="page" id="arealistpage">
            <div data-role="header" data-theme="b">
                 <h1>SQ/TR</h1>

                <a href="../Default.aspx" class='ui-btn-left ui-btn-back' data-icon='arrow-l'>Back</a>
            </div>
            <!-- /header -->
            <div data-role="content">
                <ul data-filter="true" data-inset="true" data-role="listview">
                    <li>
                        <a href="#">Design Squad Check</a>
                    </li>
                    <li>
                        <a href="#">Vendor Squad Check</a>
                    </li>
                    <li>
                        <a href="#">Business Squad Check</a>
                    </li>
                    <li>
                        <a href="#">Management Squad Check</a>
                    </li>
                    <li>
                        <a href="#">Design Transmittal</a>
                    </li>
                    <li>
                        <a href="#">Vendor Transmittal</a>
                    </li>
                    <li>
                        <a href="#">Business Transmittal</a>
                    </li>
                    <li>
                        <a href="#">Management Transmittal</a>
                    </li>
                </ul>
            </div>
            <!-- /content -->
            <div data-role="footer" data-theme="b" id="footerNavBar">
                <div class="ui-bar">
                    <a href="" data-role="button" data-icon="arrow-u" data-theme="d" style="float:right;" class="returnTopAction">Return top</a>
                </div>
            </div>
        </div>
        <!-- /page -->
    </body>

</html>
4

2 回答 2

1

将单击事件绑定到按钮并使用 jquery animate 滚动到顶部以获得滑动效果。

HTML

<a data-role="button" data-icon="arrow-u" data-theme="d" style="float:right;" class="returnTopAction">Return top</a>             

JavaScript

<script type="text/javascript">
    $(document).on('click', ".returnTopAction", function()
    {   
       $("body").animate({"scrollTop": 0});
    });
</script>
于 2013-03-02T07:03:16.660 回答
1

jQuery Mobile 中有jQuery.mobile.silentScroll()方法,它滚动到特定的 Y 位置而不触发滚动事件侦听器。此方法不执行动画滚动。

使用 jQuery Mobile 的静默滚动示例:

<html>

    <head>
        <title>SQ/TR</title>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
        <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
        <script>
            $(document).on('click', '.returnTopAction', function() {
                $.mobile.silentScroll(0);
            });
        </script>
    </head>

    <body>
        <div data-role="page" id="arealistpage">
            <div data-role="header" data-theme="b">
                 <h1>SQ/TR</h1>

                <a href="../Default.aspx" class='ui-btn-left ui-btn-back' data-icon='arrow-l'>Back</a>
            </div>
            <!-- /header -->
            <div data-role="content">
                <ul data-filter="true" data-inset="true" data-role="listview">
                    <li>
                        <a href="#">Design Squad Check</a>
                    </li>
                    <li>
                        <a href="#">Vendor Squad Check</a>
                    </li>
                    <li>
                        <a href="#">Business Squad Check</a>
                    </li>
                    <li>
                        <a href="#">Management Squad Check</a>
                    </li>
                    <li>
                        <a href="#">Design Transmittal</a>
                    </li>
                    <li>
                        <a href="#">Vendor Transmittal</a>
                    </li>
                    <li>
                        <a href="#">Business Transmittal</a>
                    </li>
                    <li>
                        <a href="#">Management Transmittal</a>
                    </li>
                </ul>
            </div>
            <!-- /content -->
            <div data-role="footer" data-theme="b" id="footerNavBar">
                <div class="ui-bar">
                    <a href="" data-role="button" data-icon="arrow-u" data-theme="d" style="float:right;" class="returnTopAction">Return top</a>
                </div>
            </div>
        </div>
        <!-- /page -->
    </body>

</html>

此外,您可以使用以下执行动画滚动的脚本:

$(document).on('click', '.returnTopAction', function() {
    $('html, body').animate({scrollTop: $("#arealistpage").offset().top}, 1000);
});

您可以检查以下基于您的代码的示例:

<html>

    <head>
        <title>SQ/TR</title>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
        <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
        <script>
            $(document).on('click', '.returnTopAction', function() {
                $('html, body').animate({scrollTop: $("#arealistpage").offset().top}, 1000);
            });
        </script>
    </head>

    <body>
        <div data-role="page" id="arealistpage">
            <div data-role="header" data-theme="b">
                 <h1>SQ/TR</h1>

                <a href="../Default.aspx" class='ui-btn-left ui-btn-back' data-icon='arrow-l'>Back</a>
            </div>
            <!-- /header -->
            <div data-role="content">
                <ul data-filter="true" data-inset="true" data-role="listview">
                    <li>
                        <a href="#">Design Squad Check</a>
                    </li>
                    <li>
                        <a href="#">Vendor Squad Check</a>
                    </li>
                    <li>
                        <a href="#">Business Squad Check</a>
                    </li>
                    <li>
                        <a href="#">Management Squad Check</a>
                    </li>
                    <li>
                        <a href="#">Design Transmittal</a>
                    </li>
                    <li>
                        <a href="#">Vendor Transmittal</a>
                    </li>
                    <li>
                        <a href="#">Business Transmittal</a>
                    </li>
                    <li>
                        <a href="#">Management Transmittal</a>
                    </li>
                </ul>
            </div>
            <!-- /content -->
            <div data-role="footer" data-theme="b" id="footerNavBar">
                <div class="ui-bar">
                    <a href="" data-role="button" data-icon="arrow-u" data-theme="d" style="float:right;" class="returnTopAction">Return top</a>
                </div>
            </div>
        </div>
        <!-- /page -->
    </body>

</html>
于 2013-03-02T07:37:22.653 回答