javascript - 如何使用 .delay(x).animate( {'opacity' :'1' },x); 淡化不透明度为 0 的每个内部元素?

标签 javascript jquery html css

我正在尝试淡入这个 div 中的每个元素,我以此为例。问题是我不知道为什么动画只在父级的内部元素中不改变。

我使用了以下 jQuery 但不起作用(也尝试了其他东西):jQuery('h1#hideme.welcome__title').delay(100).animate({'opacity':'1'}, 400);或 jQuery('.welcome__title').delay(100).animate({'opacity':'1'},400);或 jQuery('#hideme').delay(100).animate({'opacity':'1'},400);

我想专门用上面几行

<div class="section_one">
    <div class="welcome_wrapper">
        <div id="" class="welcome__container">
            <div class="welcome">
                <h1  id="hideme" class="welcome__title">Welcome to Dryft</h1>
                <div class="welcome__info">
                    <p >A Boston waterfront restaurant destination with panoramic views of the harbor. Our menu highlights
                                    many
                                    exciting flavors in some of our most classic New England dishes with a focus on fresh seafood and
                                    local
                                    ingredients.</p>
                </div>
                <button class="btn-theme">
                                Book Event<i class="fas fa-arrow-right fa-xs"></i>
                </button>
            </div>
        </div>
    </div>
</div>

我的 CSS:

#hideme {

  opacity: 0;
}

最佳答案

它似乎工作正常。我为您编辑了一些内容以检查其进展情况。我将 hidemeID 更改为 class 并将其添加到将受到影响的 3 个 elements(标题、文本和按钮)。所以我设置了 jQuery 来实现它。

HTML:

<div class="section_one">
  <div class="welcome_wrapper">
    <div id="" class="welcome__container">
      <div class="welcome">
        <h1 class="welcome__title hideme">Welcome to Dryft</h1>
        <div class="welcome__info hideme">
          <p >A Boston waterfront restaurant destination with panoramic views of the harbor. Our menu highlights
            many
            exciting flavors in some of our most classic New England dishes with a focus on fresh seafood and
            local
            ingredients.
          </p>
        </div>
        <button class="btn-theme hideme">
        Book Event<i class="fas fa-arrow-right fa-xs"></i>
        </button>
      </div>
    </div>
  </div>
</div>

CSS:

.hideme {
  opacity: 0;
}

jQuery:

$('h1.hideme').delay(100).animate({'opacity':'1'},400);
$('.welcome__info.hideme').delay(400).animate({'opacity':'1'},400);
$('.btn-theme.hideme').delay(700).animate({'opacity':'1'},400);

关于javascript - 如何使用 .delay(x).animate( {'opacity' :'1' },x); 淡化不透明度为 0 的每个内部元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57243762/

相关文章:

javascript - 在 Javascript 中一次通过一组 4 个元素循环遍历数组?

Javascript 定义一次变量

jquery - AngularJS - 在等待数据/数据计算时加载图标

html - 在导航栏中移动链接

html - 填充表格行

javascript - 上一张和下一张幻灯片的 Flexslider 位置

javascript - 对象原型(prototype)链的深度会影响性能吗?

javascript - 当有人点击搜索结果链接时,Google 如何设置 HTTP Referrer?

jquery - Bootstrap 单选按钮 - 使用 jquery 添加变量

php - 未定义索引 : is_ajax