Javascript - 复制淡入淡出

标签 javascript css function animation fade

我试图让不同的引号淡入和淡出正文副本,但也让它们保持在同一行。目前,引号只会出现在单独的一行中,而不是与之前的行相同。

(function() {

  var quotes = $(".quotes");
  var quoteIndex = -1;

  function showNextQuote() {
    ++quoteIndex;
    quotes.eq(quoteIndex % quotes.length)
      .fadeIn(2000)
      .delay(2000)
      .fadeOut(2000, showNextQuote);
  }

  showNextQuote();

})();
.quotes {
  display: none;
  overflow: hidden;
  white-space: nowrap;
}
.intro {
  width: 800px;
  overflow: hidden;
  white-space: nowrap;
}
.h2 {
  overflow: hidden;
  display: inline;
}
.intro h1,
.intro h2 {
  overflow: hidden;
  vertical-align: top;
  font-size: 24px;
}
.intro h1 {
  font-weight: bold;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="intro">
  <h1>Hello, my name is  I am a</h1>
  <h2 class="quotes">quote 1</h2>
  <h2 class="quotes">quote 2</h2>
  <h2 class="quotes">quote 3</h2>
  <h1>currently based in London, GBR</h1>
</div>

http://jsfiddle.net/n4mKw/4220/

最佳答案

只需将 display: inline 添加到此 block :

.intro h1,
.intro h2 {
  overflow: hidden;
  vertical-align: top;
  font-size: 24px;
  display: inline;
}

例子...

(function() {

  var quotes = $(".quotes");
  var quoteIndex = -1;

  function showNextQuote() {
    ++quoteIndex;
    quotes.eq(quoteIndex % quotes.length)
      .fadeIn(2000)
      .delay(2000)
      .fadeOut(2000, showNextQuote);
  }

  showNextQuote();

})();
.quotes {
  display: none;
  overflow: hidden;
  white-space: nowrap;
}

.intro {
  width: 800px;
  overflow: hidden;
  white-space: nowrap;
}

.intro h1,
.intro h2 {
  overflow: hidden;
  vertical-align: top;
  font-size: 24px;
  display: inline;
}

.intro h1 {
  font-weight: bold;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<div class="intro">
  <h1>Hello, my name is  I am a</h1>
  <h2 class="quotes">design addict</h2>
  <h2 class="quotes">avid doodler</h2>
  <h2 class="quotes">casual coder</h2>
  <h1>currently based in London, GBR</h1>
</div>

关于Javascript - 复制淡入淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39701940/

相关文章:

javascript - jQuery 查找/替换而不改变原始文本

javascript - 我的异步函数没有等待 Firebase 的 promise

Javascript - 在所有函数的输入上以编程方式执行方法

将一维字符串复制到二维数组元素中

c++ - 与 C++ 中的 virtual 关键字混淆

javascript - 如何检查日期时间?

javascript - Visual Studio javascript 调试不起作用

css - Safari iOS 中出现奇怪的 "filter:grayscale"错误?

html - 仅使用 CSS 将 <p> 中的文本移动到 <p> 宽度的末尾

html - 为什么我的 html 文件不显示 JS 和 CSS?