代码之家  ›  专栏  ›  技术社区  ›  Baudet

css文本动画问题

  •  -1
  • Baudet  · 技术社区  · 7 年前

    下面的代码应该在向下滚动时显示“专用人员”,因为某些原因它在我的浏览器中不起作用?我是不是脑子里忘了一个参考?当我使用代码笔时,它工作得很好,但在任何其他浏览器中它都不显示任何内容。这背后的原因是什么,我该如何解决这个铬浏览器。

    $(function() {
      var text = $(".text");
      $(window).scroll(function() {
        var scroll = $(window).scrollTop();
    
        if (scroll >= 10) {
          text.removeClass("hidden");
        } else {
          text.addClass("hidden");
        }
      });
    });
    @import url('https://fonts.googleapis.com/css?family=Muli:300,400,700');
    
    * {
      margin: 0;
      padding: 0;
    }
    body {
      background-color: #000;
      height: 200vh;
      font-family: 'Muli', sans-serif;
    }
    .text {
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translateX(-50%) translateY(-50%);
      list-style: none;
      border-bottom: 0;
    }
    
    .text.hidden {
      border-bottom: 1px solid #fff;
    }
    
    .text li {
      display: inline-block;
      float: left;
      font-weight: 700;
      font-size: 2em;
      color: #fff;
      opacity: 1;
      transition: all 0.5s ease-in-out;
      max-width: 2em;
    }
    .text.hidden li.spaced {
      padding-left: 0;
    }
    .text li.spaced {
      padding-left: 0.5em;
    }
    
    .text.hidden li.ghost {
      opacity: 0;
      max-width: 0;
    }
    <ul class="text hidden">
      <li>D</li>
      <li class="ghost">e</li>
      <li class="ghost">d</li>
      <li class="ghost">i</li>
      <li class="ghost">c</li>
      <li class="ghost">a</li>
      <li class="ghost">t</li>
      <li class="ghost">e</li>
      <li class="ghost">d</li>
      <li class="spaced">P</li>
      <li class="ghost">e</li>
      <li class="ghost">o</li>
      <li class="ghost">p</li>
      <li class="ghost">l</li>
      <li class="ghost">e</li>
    </ul>
    2 回复  |  直到 7 年前
        1
  •  1
  •   לבני מלכה    7 年前

    你好像忘了 Jquery 脚本:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    

    这里是jsfiddle: https://jsfiddle.net/8dc7toLn/

    $(function() {
      var text = $(".text");
      $(window).scroll(function() {
        var scroll = $(window).scrollTop();
    
        if (scroll >= 10) {
          text.removeClass("hidden");
        } else {
          text.addClass("hidden");
        }
      });
    });
    @import url('https://fonts.googleapis.com/css?family=Muli:300,400,700');
    
    * {
      margin: 0;
      padding: 0;
    }
    body {
      background-color: #000;
      height: 200vh;
      font-family: 'Muli', sans-serif;
    }
    .text {
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translateX(-50%) translateY(-50%);
      list-style: none;
      border-bottom: 0;
    }
    
    .text.hidden {
      border-bottom: 1px solid #fff;
    }
    
    .text li {
      display: inline-block;
      float: left;
      font-weight: 700;
      font-size: 2em;
      color: #fff;
      opacity: 1;
      transition: all 0.5s ease-in-out;
      max-width: 2em;
    }
    .text.hidden li.spaced {
      padding-left: 0;
    }
    .text li.spaced {
      padding-left: 0.5em;
    }
    
    .text.hidden li.ghost {
      opacity: 0;
      max-width: 0;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <ul class="text hidden">
      <li>D</li>
      <li class="ghost">e</li>
      <li class="ghost">d</li>
      <li class="ghost">i</li>
      <li class="ghost">c</li>
      <li class="ghost">a</li>
      <li class="ghost">t</li>
      <li class="ghost">e</li>
      <li class="ghost">d</li>
      <li class="spaced">P</li>
      <li class="ghost">e</li>
      <li class="ghost">o</li>
      <li class="ghost">p</li>
      <li class="ghost">l</li>
      <li class="ghost">e</li>
    </ul>
        2
  •  0
  •   Claire    7 年前

    你的代码在我的浏览器中运行得很好。如果还没有,请记住包含jquery。

    走到这里: https://code.jquery.com/

    得到这个:

    <script
      src="https://code.jquery.com/jquery-3.3.1.min.js"
      integrity="[insert]"
      crossorigin="anonymous">
    </script>
    

    并将其添加到文档中。