简体   繁体   English

在淡入淡出之间淡入/淡出

[英]Fade in/out in between fades

so here is the thing. 所以这是东西。 I saw this website: http://laneandassociates.co/english-mustard-scottish-oats and I absolutely can't figure out how they do their fades. 我看到了这个网站: http : //laneandassociates.co/english-mustard-scottish-oats ,我绝对不知道它们是如何褪色的。

The great thing about their fade effect is, that it can be "stopped" in the middle of the fading process by clicking. 关于它们的淡入淡出效果的妙处在于,可以在淡入淡出过程的中间通过单击将其“停止”。

For a better understanding: Let's assume the fadeIn duration is 1000. If I click when the fadeIn is at (for example) 700, the fadeIn immediately stops at 700 and begins to fade back out to 0. Then the fadeIn of the next image starts from 0. It just looks really smooth. 为了更好地理解:假设fadeIn的持续时间为1000。如果我单击(例如)fadeIn为700时,fadeIn立即在700处停止并开始逐渐淡出为0。然后开始下一张图像的fadeIn从0开始。看起来真的很流畅。

Problem is, I can't even find the code for the fades. 问题是,我什至找不到淡入淡出的代码。 Can someone show me how they made it, so I can take a look at it and learn it? 有人可以告诉我他们是如何制作的,以便我可以看看并学习吗?

Thank you in advance. 先感谢您。

That site is using a cubic-bezier CSS animation. 该站点使用立方贝塞尔曲线 CSS动画。

This is achieved with some CSS like the following: 这可以通过以下CSS实现:

.element.animated {
    opacity: 0;
    transition: opacity 0.8s cubic-bezier(0.645, 0.045, 0.355, 1),transform 0.8s cubic-bezier(0.645, 0.045, 0.355, 1),visibility 0.8s cubic-bezier(0.645, 0.045, 0.355, 1);
    visibility: hidden;
}

The hard part can be calculating the correct parameters for the type of animation you want. 困难的部分可能是为所需的动画类型计算正确的参数。 You can use this site to do that . 您可以使用此网站来做到这一点

Here is a demo of another animation . 这是另一个动画演示


For removing animation on hover: 要在悬停时删除动画:

.element.animated:hover {
    opacity: 1;
    transition: none;
}

So one way you can do fading with jQuery: https://api.jquery.com/category/effects/fading/ . 因此,您可以使用jQuery进行淡入淡出的一种方法是: https : //api.jquery.com/category/effects/fading/ You can use the fadeIn method to fade in an element and the fadeOut method to fade out an element. 您可以使用fadeIn方法淡入一个元素,并使用fadeOut方法淡出一个元素。 To make the element stop fading on a click you could do something like this: 要使元素在单击时停止褪色,可以执行以下操作:

$('mySelector').on('click', function() {
    myElement.stop(); // This stops the fade from continuing
});

By using the stop method you can pause an animation or complete it early. 通过使用stop方法,您可以暂停动画或尽早完成动画。 For more details on stop animation check out the docs here: https://api.jquery.com/stop/ . 有关stop动画的更多详细信息,请在此处查看文档: https : //api.jquery.com/stop/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM