简体   繁体   English

我应该如何在基本HTML页面中实现jScroll?

[英]How should I implement jScroll in a basic HTML page?

I'm trying to replicate this useless website: http://endless.horse , but the jScript documentation does not do a great job of explaining how to implement it. 我正在尝试复制这个无用的网站: http ://endless.horse,但是jScript文档并没有很好地解释如何实现它。

Basically, I need a block of text "Body" to be at the top, then for a block of text "Legs" to appear infinitely (as placeholders) (see website). 基本上,我需要一个文本块“Body”位于顶部,然后一块文本“Legs”无限地出现(作为占位符)(参见网站)。

I've tried adding what the website says: http://jscroll.com , but it only says "[element].jscroll()" and that's it. 我已经尝试添加网站上的内容: http ://jscroll.com,但它只是说“[element] .jscroll()”就是这样。 I've also tried copying the code from the website, but that also doesn't work. 我也试过从网站上复制代码,但这也行不通。

Here is the code I'm using: DIV that should scroll: 这是我正在使用的代码:应该滚动的DIV:

<div class="jscroll">
    <pre>
        <h1>Body</h1>
    </pre>
    <a href="rest.html"></a>
</div>

rest.html: rest.html:

<pre>
    Legs
</pre>
<a href="rest.html"></a>

Code was taken from the website 代码取自网站

javascript/jquery/jscroll: 使用Javascript / jQuery的/ jscroll:

$(function() {
    $('.jscroll').jscroll({
        autoTrigger: true,
        padding: 2000px,
        nextSelector: "rest.html"
    });    
});

I thought I would get a scrolling webpage with "Body" and "Legs", but I got just "Body" instead. 我想我会得到一个带有“Body”和“Legs”的滚动网页,但我只是选择了“Body”。

Assuming that you have included the right js and you run your script when the document is ready, the following code works for you: 假设您已包含正确的js并在文档准备就绪时运行脚本,则以下代码适用于您:

<script type="text/javascript" src="https://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="https://unpkg.com/jscroll@2.4.1/dist/jquery.jscroll.min.js"></script>

<div class="jscroll">
    <pre>
        <h1>Body</h1>
    </pre>
    <a href="rest.html"></a>
</div>
<script>
document.addEventListener("DOMContentLoaded", function(event) { 
  $(function() {
      $('.jscroll').jscroll({
          autoTrigger: true,
          padding: 2000,
          nextSelector: "a:last"
      });   
  }); 
});

</script>

Basically, you need to change your nextSelector to be more specific and you must put a real jquery selector. 基本上,您需要将nextSelector更改为更具体,并且必须放置一个真正的jquery选择器。 'a:last' always selects the last a tag that is available. 'a:last'总是选择最后a可用a标签。 Also, you need to change 2000px to 2000 . 此外,您需要将2000px更改为2000 this code worked for me. 这段代码对我有用。 Don't forget to include more characters to your rest.html output. 不要忘记在rest.html输出中包含更多字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM