1

我试图为在 iPad 上呈现的网站创建一个简单的两列布局,但我遇到了一些问题。我不知道如何描述这个,所以我链接到下面的截图来开始:

http://i41.tinypic.com/3093ecw.jpg

本质上,当我到达文档的底部时,浏览器正在提升整个文档,并在后台显示某种构建。

我将如何防止这种情况发生?即当用户滚动到页面底部时,不再滚动,简单吗?

我的代码如下:

<html>
<head>
    <style type="text/css">
        html, body {
            padding: 0;
            margin: 0;
        }
        #container {
            width: 820px;
            margin: 0 auto;
            /*border: 1px solid red;*/
        }
        #header {
            text-align: center;
            width: 100%;
            border: 1px solid black;
            height: 100px;
            margin-bottom: 10px;
        }
        #left-column {
            height: 100%;
            overflow: scroll;
            float:left;
            width:200px;
            border: 1px solid black;
            -webkit-overflow-scrolling: touch;
        }
        #right-column {
            height: 100%;
            overflow: scroll;
            float: right;
            width: 600px;
            border: 1px solid black;
            -webkit-overflow-scrolling: touch;
        }
    </style>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $(document).bind('touchmove', function(e) {
                console.log("PREVENTING DEFAULT");
                e.preventDefault();
            });

            bindScrollableColumn('#left-column');
            bindScrollableColumn('#right-column');
            resizeScrollableColumns(getSizeAboveLeftScrollableColumn(), getSizeAboveRightScrollableColumn());

            window.onorientationchange = function() {
                resizeScrollableColumns(getSizeAboveLeftScrollableColumn(), getSizeAboveRightScrollableColumn());
            }
        });

        function resizeScrollableColumns(sizeAboveLeftScrollableColumn, sizeAboveRightScrollableColumn) {
            var newLeftScrollableColumnHeight = window.innerHeight - sizeAboveLeftScrollableColumn;
            var newRightScrollableColumnHeight = window.innerHeight - sizeAboveRightScrollableColumn;
            $('#left-column').attr('style', 'height:' + newLeftScrollableColumnHeight + 'px !important');
            $('#right-column').attr('style', 'height:' + newRightScrollableColumnHeight + 'px !important');
        }

        function getSizeAboveLeftScrollableColumn() { return 112; }
        function getSizeAboveRightScrollableColumn() { return 112; }

        function bindScrollableColumn(columnSelector) {
            $(columnSelector).bind('touchstart', function(e) {
              if (e.currentTarget.scrollTop === 0) {
                e.currentTarget.scrollTop = 1;
              } else if (e.currentTarget.scrollHeight === e.currentTarget.scrollTop + e.currentTarget.offsetHeight) {
                e.currentTarget.scrollTop -= 1;
              }
            });

            $(columnSelector).bind('touchmove', function(e) {
                console.log("stopping propagation");
                e.stopPropagation();
            });
        }
    </script>
</head>
<body>
<div id="container">
    <div id="header">
        HEADER
    </div>
    <div id="left-column">
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        ghdjdsi<br />
    </div>
    <div id="right-column">
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        abcdefg<br />
        ghdjdsi<br />
    </div>
</div>
</body>
</html>

如您所见,布局由标题和两列组成。javascript 将列设置为与视口底部对齐,首先是在页面加载和方向更改时。如果我在列外的背景上滚动,JS 也会停止文档滚动。

但是,如果我将两列滚动到底部,然后继续在它们之间切换并滚动,则会产生上图中显示的问题。

任何人都可以帮忙吗?

4

2 回答 2

0

您是否考虑过使用像JQuery Mobile这样的框架来帮助布局?1.3 版添加了一些响应式功能,包括网格。网格将有助于您的列方案。

于 2013-05-28T14:09:38.933 回答
0

我会查看 iframe,它们真的很有帮助。它们也是 HTML 的一部分

http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe

于 2013-05-28T14:10:40.623 回答