代码之家  ›  专栏  ›  技术社区  ›  Suleman Khalid

jqueryissue创建闪烁的文本和图像

  •  0
  • Suleman Khalid  · 技术社区  · 6 年前

    我使用jquery,这样每当用户将鼠标悬停在缩略图/视频上时,文本就会淡入淡出。如果用户缓慢地将鼠标悬停在项目上,效果会很好,文本会在图像上淡入淡出。但是,如果用户在屏幕上快速移动光标到多个图像上,则文本将在网站标题中而不是在图像中闪烁。

    以下是网站链接: https://sulemankhalid.com/home.html

      <a href="animation.html">
            <div class="cell" id="animation">
              <div id="video-container" style="z-index: -1;">
                <video autoplay loop muted style="width: 100%; height:100%;">
                  <source id="mp4" src="https://sulemankhalid.com/thumbnails/animation.mp4" type="video/mp4">
                </video>
              </div>
              <div class="info">
                <h2>Animation &</h2>
                <h2>Motion Graphics</h2>
                <p>Shion Uino left Sushi Saito, a restaurant many consider to be one of the best in the world, to chart his own path in New York.</p>
              </div>
            </div>
          </a>
    

    Jquery示例:

      $("#animation h2").hide();
            $("#animation p").hide();
            $("#animation").hover(function(){
              $("#animation h2").fadeIn(400);
              $("#animation p").fadeIn(400);
              $("#animation video").fadeTo("slow", 0.1);
            }, function(){
              $("#animation h2").fadeOut(400);
              $("#animation p").fadeOut(400);
              $("#animation video").fadeTo("slow", 1);
            });
    

    如果有任何帮助,我将不胜感激

    2 回复  |  直到 6 年前
        1
  •  0
  •   Ted    6 年前

    在父对象上缺少绝对位置信息的相对位置。

    在CSS定义中 .cell position: relative; 像这样:

    .cell {
        background-color: #23384b;
        background-size: 100%;
        float: left;
        width: 325px;
        height: 325px;
        margin: 1.72%;
        transition: 0.4s;
        overflow: visible;
        cursor: pointer;
        position: relative;
    }
    

    .info

    .info {
        padding: 20px;
        position: absolute;
        top: 80px;
        left: 0px;
        text-align: right;
        font-family: Roboto;
        color: white;
    }
    
        2
  •  1
  •   Merak Marey    6 年前

    https://api.jquery.com/hover/ )您将在第一个演示中看到,它们与您页面上的“缺陷”相同。这实际上不是一个缺陷,而是jQuery的一个特性。你要做的是在开始下一个动画之前停止正在运行的动画。看到了吗 https://api.jquery.com/stop/