为什么这个 html、css 和 javascript 不能与 iScroll4 一起使用?

发布于 2024-11-26 22:21:33 字数 1057 浏览 3 评论 0原文

我正在建立一个移动网站。我需要标题为位置:固定(但不支持移动),所以我使用 iScroll4 因为它似乎是我正在寻找的。由于某种原因,我无法弄清楚如何实现它。

这是我的 HTML:

<html>
<head>
<!--includes the iscroll.js file-->
</head>
<body>
<div id="header">
<!--header contents-->
</div>
<div id="wrapper">
<div id="scroller">
<!--a bunch of html that you probably don't care to see-->
</div>
</div>

这是我的 CSS:

#scroller {
    position: absolute;
}

#wrapper {
    position: absolute;
    width: 100%;
    top: 0px;
    left: 0;
    overflow: auto;
}

#header {
    background: #4B92DB;
    border: none;
    height: 175px;
    opacity: 1;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
}

这是我的 Javascript:

var myScroll;
            function loaded() {
            myScroll = new iScroll('wrapper');
            }

            document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

如果您有任何想法,我们将不胜感激。

I am building a mobile website. I need the header to be position:fixed (but being mobile that is not supported) so I am using iScroll4 because it seems to be what I am looking for. For some reason I am not able to figure out how to implement it.

Here is my HTML:

<html>
<head>
<!--includes the iscroll.js file-->
</head>
<body>
<div id="header">
<!--header contents-->
</div>
<div id="wrapper">
<div id="scroller">
<!--a bunch of html that you probably don't care to see-->
</div>
</div>

Here is my CSS:

#scroller {
    position: absolute;
}

#wrapper {
    position: absolute;
    width: 100%;
    top: 0px;
    left: 0;
    overflow: auto;
}

#header {
    background: #4B92DB;
    border: none;
    height: 175px;
    opacity: 1;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
}

And here is my Javascript:

var myScroll;
            function loaded() {
            myScroll = new iScroll('wrapper');
            }

            document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

If you have any ideas they would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故人的歌 2024-12-03 22:21:33

你的 loaded() 在哪里被调用?这(或类似的东西)可能会有所帮助:

<body onload="loaded()">

Where's your loaded() being called? This (or something like it) might help:

<body onload="loaded()">
新人笑 2024-12-03 22:21:33

阅读 iScroll4 官方页面可能会对您有所帮助。 http://cubiq.org/iscroll-4

部分:入门。有 3 种方法可以使其工作:

  1. onDOMContentLoaded 事件触发 iscroll
  2. onLoad 事件触发
  3. 内联,将代码放在要滚动的 html 位下方

所有代码都在提到的页面上。

Reading iScroll4 official page might help you. http://cubiq.org/iscroll-4

Section: Getting started. There are 3 ways to make it work:

  1. onDOMContentLoaded event to trigger iscroll
  2. onLoad event to trigger
  3. inline, place the code below the html bit you want to scroll

All codes are just on the page mentioned.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文