javascript - 使用 jQuery fadeOut() 缩放动画

标签 javascript jquery css animation fadeout

我搜索了一段时间但没有找到关于此的帖子:我正在使用 jQuery fadeOut()动画元素。

我想使用 jQuery 的 fadeOut() 函数淡出 scale1.75 (175%) 的元素。目前它是一个常见的淡出动画,但我希望淡出动画向外扩展(元素膨胀)。

我已经使用 keyframes 制作了一个带有 CSS 动画的示例(lightblue 元素)。我想用 fadeOut() 解决动画(也许你必须向下滚动代码片段才能看到这个例子),这可能吗?我希望这已经足够清楚了。

$('.hide').click(function() {
  $('.animate').fadeOut(500);
});

$('.show').click(function() {
  $('.animate').fadeIn(500);
});
.animate {
  width: 150px;
  height: 150px;
  background-color: lightcoral;
  margin-top: 20px;
}

.animate--css {
  background-color: lightblue;
}

.animate--css {
  width: 150px;
  height: 150px;
  background-color: lightblue;
  margin-top: 20px;
  animation: zoomOut 1s infinite;
}

@keyframes zoomOut {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(1.75);
    opacity: 0;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="hide">Fade out</button>
<button class="show">Fade in</button>
<div class="animate"></div>
<div class="animate--css"></div>

最佳答案

您可以使用 start 在元素淡出之前应用 CSS:

$('.hide').click(function() {
  $('.animate').fadeOut({'start':function() {$(this).css('transform','scale(1.75)') },'duration':500});
});

$('.show').click(function() {
  $('.animate').fadeIn({'start':function() {$(this).css('transform','scale(1)') },'duration':500});
});
.animate {
  width: 150px;
  height: 150px;
  background-color: lightcoral;
  margin-top: 20px;
  transition:0.5s all;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="hide">Fade out</button>
<button class="show">Fade in</button>
<div class="animate"></div>

关于javascript - 使用 jQuery fadeOut() 缩放动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51268940/

相关文章:

html - 如何通过 CSS 更改 nvd3 图表填充和描边颜色

jquery - 如何鼠标悬停一个 div,当另一个实际悬停时,反之亦然

javascript - Jquery.pwstrength 密码强度指示器规则不起作用

javascript - 使用返回不同结果的 TextDecoder/TextEncoder 将 ArrayBuffer 转换为 String 然后返回 ArrayBuffer

javascript - 单击表行上的按钮并在模式窗口中显示值

jquery - 如何更改横幅的宽度

javascript - 您可以使用 jquery 或 javaScript 读取此 JSON

css - 通过 vite 导入获取原始字符串值

javascript - DOM 操作是否异步(当使用浏览器提供的 API 时,如 getElementById 或appendChild)?

javascript - JQuery ajax stoppen in $.when 服务器返回 500 错误