【问题标题】:I need help making a scroll button [closed]我需要帮助制作滚动按钮[关闭]
【发布时间】:2019-08-08 01:16:58
【问题描述】:

我想制作一个类似这个网站上的滚动按钮: https://codepad.co/snippet/scroll-down-button-css 我已经复制了所有代码,但是当我在浏览器中打开网站时,按钮不起作用,即使我逐字复制了所有内容。我不知道足够的JS来解决这个问题。感谢您的帮助。

【问题讨论】:

    标签: javascript css button scroll


    【解决方案1】:

    你说你一个字一个字地复制了所有的东西,但是,你的笔记本电脑上不工作,只是示例代码。

    或者您正在现有网站上对其进行测试??

    在案例 1 中> 确保在页面中包含 jQuery 库以确保所有功能都正常工作

    在案例 2 中 > 您必须更改滚动的方向,如您所见

    {scrollTop: $('section.ok').offset().top }, 'slow');
    

    就像你可以看到滚动将被定向到名为“ok”的类的部分

    所以请确定你的情况并祝你好运

    【讨论】:

    • 请查看此页面:How to Answer
    • 好的。我只是刚刚了解了 HTML 和 CSS,而不是任何 javascript。我想我可以复制它并像 CSS 文件一样链接它。我将尝试找出这个 jQuery 库现在是什么。谢谢。编辑:案例1
    • @rala 我确实检查了谢谢,但你能更清楚你的意思吗,谢谢
    • 我包含了 jQuery 库并且它工作正常。但是上传到github后,按钮就失效了。
    • 它不再在您的设备上或在线上工作了?
    【解决方案2】:

    您必须在本地使用 jquery 库文件或使用 cdn 地址。没有 jquery 滚动功能将无法工作。

    jquery cdn 路径为:-http://code.jquery.com/jquery-1.12.1.min.js

    只需复制此脚本标记并在您的函数之前使用。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
        body {
      background-color: #000;
    }
    
    *,
    :after,
    :before {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }
    
    section {
      height: 100vh;
      width: 100%;
      display: table;
      
    }
    section.ok{
      background-color: #555;
    }
    
    p{
      color: white;
      font-family: arial;
      display: table-cell;
      text-align: center;
      vertical-align: middle;
    }
    
    .scroll-down {
      opacity: 1;
      -webkit-transition: all .5s ease-in 3s;
      transition: all .5s ease-in 3s;
    }
    
    .scroll-down {
      position: absolute;
      bottom: 30px;
      left: 50%;
      margin-left: -16px;
      display: block;
      width: 32px;
      height: 32px;
      border: 2px solid #FFF;
      background-size: 14px auto;
      border-radius: 50%;
      z-index: 2;
      -webkit-animation: bounce 2s infinite 2s;
      animation: bounce 2s infinite 2s;
      -webkit-transition: all .2s ease-in;
      transition: all .2s ease-in;
    }
    
    .scroll-down:before {
        position: absolute;
        top: calc(50% - 8px);
        left: calc(50% - 6px);
        transform: rotate(-45deg);
        display: block;
        width: 12px;
        height: 12px;
        content: "";
        border: 2px solid white;
        border-width: 0px 0 2px 2px;
    }
    
    @keyframes bounce {
      0%,
      100%,
      20%,
      50%,
      80% {
        -webkit-transform: translateY(0);
        -ms-transform: translateY(0);
        transform: translateY(0);
      }
      40% {
        -webkit-transform: translateY(-10px);
        -ms-transform: translateY(-10px);
        transform: translateY(-10px);
      }
      60% {
        -webkit-transform: translateY(-5px);
        -ms-transform: translateY(-5px);
        transform: translateY(-5px);
      }
    }
        </style>
    </head>
    <body>
        <section>
            <p>SCROLL DOWN CSS</p>
            <a href="#" class="scroll-down" address="true"></a>
            </section>
            <section class="ok">
            <p>OK SCROLL !</p>
            </section>
         <script src="http://code.jquery.com/jquery-1.12.1.min.js"></script>   
            <script>
             $(function() {
        $('.scroll-down').click (function() {
          $('html, body').animate({scrollTop: $('section.ok').offset().top }, 'slow');
          return false;
        });
      });
            </script>
    </body>
    </html>

    【讨论】:

    • 好的。我只是刚刚了解了 HTML 和 CSS,而不是任何 javascript。我想我可以复制它并像 CSS 文件一样链接它。我将尝试找出这个 jQuery 库现在是什么。谢谢。
    • 祝你一切顺利!!!
    • 我按照你说的做了,它对我有用。但是上传到github后,按钮就失效了!
    猜你喜欢
    • 2021-09-26
    • 2023-02-25
    • 2022-09-23
    • 2017-04-04
    • 1970-01-01
    • 2020-01-02
    • 2011-06-11
    • 1970-01-01
    • 2020-11-12
    相关资源
    最近更新 更多