【问题标题】:jQuery animations in Flexbox - animation not runningFlexbox 中的 jQuery 动画 - 动画未运行
【发布时间】:2018-04-21 17:58:15
【问题描述】:

我使用 Flexbox 创建了一个方形 div 网格来复制打印图像,并希望每个方形在页面滚动到某个点时从最高容器 div 的顶部向下滑动。尽管我知道浏览器正在获取 .scroll 功能,但这并没有触发,因为我有一个控制台日志正在运行。我一直在努力让一个 div 在这一点上滑动。 Flexbox 是超级严格还是我遗漏了什么?这是代码。

<script>
  $(document).ready(function(){
      $( this ).scroll(function() {
        if ($(this).scrollTop() > 50){
        $( "#small-twelve" ).slideDown( 5000, function(){
          console.log("scrolled!")
        })
        };
      });
    });
</script>    

HTML

<div class="square-container">
            <div class="square-smalls-container">
              <div class="small-eleven">
                <div class="text">
                  <h3>+63.5%</h3>
                  <p>more computer &amp; data processing <br/> services</p>
                </div>
              </div>
              <div class="small-twelve" id="small-twelve">
                <div class="text">
                  <h3>+49.0%</h3>
                  <p>other freight &amp; <br/>port services</p>
                </div>
              </div>
            </div>
              <div class="long-one">
                <div class="text">
                  <h3>+247.9%</h3>
                  <p>more film &amp; television <br/>distribution services</p>
                </div>
              </div>
            </div>
      </div>

CSS

.square-smalls-container{
        flex-direction: row;
        display: flex;
        flex: 2;
        box-sizing: border-box;
        position: relative;
      }
.small-one, .small-two, .small-three, .small-four, .small-five, .small-six, .small-seven, .small-eight, .small-nine, .small-ten, .small-eleven, .small-twelve{
        display: flex;
        box-sizing: border-box;
        padding: 10px;
        flex-basis: 18%;
        margin: 0 auto;
        position: relative;
      }

.small-eleven, .small-twelve{
        flex: 1;
        margin-left: 2%;
        margin-right: 2%;
      }

【问题讨论】:

    标签: jquery animation flexbox


    【解决方案1】:

    你正在通过它的 id 滑动一个 div

        $( "#small-twelve" ).slideDown( 5000, function(){
          console.log("scrolled!")
        })
    

    不知道你为什么期望别人搬家。检查您的 jQuery 选择器。这与 flexbox 无关 :-)

    在一些 div 中添加了 slideMe 类并更新了您的 jQuery 选择器以选择所有具有 slideMe 类的 div:

     <div class="square-container">
            <div class="square-smalls-container">
              <div class="slideMe small-eleven">
                <div class="text">
                  <h3>+63.5%</h3>
                  <p>more computer &amp; data processing <br/> services</p>
                </div>
              </div>
              <div class="slideMe small-twelve" id="small-twelve">
                <div class="text">
                  <h3>+49.0%</h3>
                  <p>other freight &amp; <br/>port services</p>
                </div>
              </div>
            </div>
              <div class="slideMe long-one">
                <div class="text">
                  <h3>+247.9%</h3>
                  <p>more film &amp; television <br/>distribution services</p>
                </div>
              </div>
            </div>
      </div>
    

    还有 JS:

       <script>
       $(document).ready(function(){
          $( this ).scroll(function() {
            if ($(this).scrollTop() > 50){
            $( ".slideMe" ).slideDown( 5000, function(){
              console.log("scrolled!")
            })
            };
          });
        });
        </script>    
    

    【讨论】:

    • 我现在只是想让一个移动 - 一旦我得到这个工作,我想安排其他 div 以不同的速率滑动以获得不同的效果。我将 .slideMe 添加到课程中,但它仍然无法正常工作。 :(
    • 是的 - 我完全按照您提供的方式使用了上述所有代码。
    • 所以我可能有一个想法——当我使用内置方法 .slideUp 时,div 向上滑动并消失。是不是因为 div 已经可见所以它没有向下滑动?您将如何隐藏它以使其在滚动时显示?
    • 几种方式。 1. 初始加载时用 CSS 隐藏 2. 加载后用 JS 调用 .hide() 隐藏。
    猜你喜欢
    • 2015-06-25
    • 1970-01-01
    • 1970-01-01
    • 2012-07-06
    • 2019-03-31
    • 2011-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多