抖音资讯

douyinzx

html动画效果代码(html网页制作动态效果)

iseeyu2年前 (2024-05-05)抖音资讯153

主要利用CSS3-animation + JS实现效果,只是提供思路,具体细节可以参考
实现效果:

 


css3-animation属性,可实现动画效果,如下:
 

[CSS] 纯文本查看 复制代码

?

.demo{

animation: 动画1,动画2;

}
上面可以实现动画效果,但是不可控制,只能自动播放,于是看下面:
 

[JavaScript] 纯文本查看 复制代码

?

// 灵动岛对应dom

const box = document.querySelector(".demo");

// 以类名定义所有动画类型,以类名切换,实现动画切换

const animationList = ["longer", "divide", "fusion", "bigger"];

box.addEventListener("click", () => {

box.classList.add(animationList[index]);

});

let index = 0;

// 每一个动画结束都会触发此事件(包括子元素及不同属性的动画结束时)

box.addEventListener("animationend", (e) => {

if (

e.animationName === "divide-right" ||

e.animationName === "fusion-right"

) {

return;

}

index++;

setTimeout(() => {

if (index <= animationList.length - 1) {

box.classList.add(animationList[index]);

} else {

index = 0;

}

}, 800);

});
JS控制动画的三种方式:
1.直接覆盖 animation

[CSS] 纯文本查看 复制代码

?

1

box.style.animation = `longer 800ms ease-in-out`;
如果动画效果较多,那就写的比较长了,建议封装CSS类,通过切换CSS类名实现动画效果


2.通过切换CSS类名,上面说过了,把不同动画封装在不同类里面,直接切换
 

[CSS] 纯文本查看 复制代码

?

1

box.classList.toggle('longer');
3.animationPlayState属性
 

[CSS] 纯文本查看 复制代码

?

 

1

2

box.style.animationPlayState="paused"

// runing播放,paused暂停。

 


但是只支持单动画播放


动画结束后如何让界面停留在结束时的状态呢?
 

[CSS] 纯文本查看 复制代码

?

 

1

animation-fill-mode:forwards;

 


完整代码:
 

[HTML] 纯文本查看 复制代码

?

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<title>灵动岛</title>

<style>

* {

margin: 0;

padding: 0;

}

#iphone14pro {

position: relative;

margin: auto;

width: 974px;

height: 876px;

overflow: hidden;

background-image: url([img]https://www.qcodes.cn/wp-content/uploads/2022/09/2022091405393859.png[/img]);

}

.demo {

width: 320px;

margin-top: 72px;

margin: 72px auto 0;

background-color: red;

height: 80px;

border-radius: 40px;

background-color: #272729;

position: relative;

}

.demo::after {

position: absolute;

content: " ";

right: 0;

width: 80px;

height: 100%;

border-radius: 80px;

background-color: #272729;

}

/* 变长 */

.longer {

animation: longer 800ms ease-in-out forwards;

}

@keyframes longer {

0% {

}

60% {

width: 50vw;

}

80% {

transform: scaleX(1.04);

}

100% {

transform: scaleX(1);

width: 50vw;

}

}

/* 分离 */

.divide {

animation: divide-left 800ms ease-in-out forwards;

}

@keyframes divide-left {

0% {

}

40% {

transform: scaleX(1.1);

}

 

100% {

transform: scaleX(1);

}

}

.divide::after {

animation: divide-right 800ms ease-in-out forwards;

}

@keyframes divide-right {

0% {

}

40% {

transform: scaleX(1.1);

}

 

100% {

transform: scaleX(1);

right: -100px;

}

}

/* 融合 */

.fusion {

animation: fusion-left 800ms ease-in-out forwards;

}

@keyframes fusion-left {

0% {

}

40% {

transform: scaleX(1.1);

}

 

100% {

transform: scaleX(1);

}

}

.fusion::after {

animation: fusion-right 800ms ease-in-out forwards;

}

@keyframes fusion-right {

0% {

right: -100px;

}

40% {

transform: scaleX(1.1);

}

 

100% {

transform: scaleX(1);

right: 0;

}

}

/* 变大 */

.bigger {

animation: bigger 800ms ease-in-out forwards;

}

@keyframes bigger {

0% {

}

60% {

width: 81vw;

height: 400px;

border-radius: 100px;

}

80% {

transform: scaleX(1.04);

}

100% {

width: 81vw;

height: 400px;

border-radius: 100px;

transform: scaleX(1);

}

}

.bigger::after {

display: none;

}

</style>

</head>

<body>

<div id="iphone14pro">

<div class="demo"></div>

</div>

<script>

// 灵动岛对应dom

const box = document.querySelector(".demo");

 

const animationList = ["longer", "divide", "fusion", "bigger"];

box.addEventListener("click", () => {

box.classList.add(animationList[index]);

});

let index = 0;

// 每一个动画结束都会触发此事件(包括子元素及不同种类属性的动画)

box.addEventListener("animationend", (e) => {

if (

e.animationName === "divide-right" ||

e.animationName === "fusion-right"

) {

return;

}

index++;

setTimeout(() => {

if (index <= animationList.length - 1) {

box.classList.add(animationList[index]);

} else {

index = 0;

}

}, 800);

});

</script>

</body>

</html>

扫描二维码推送至手机访问。

版权声明:本文由西安泽虎代运营发布,如需转载请注明出处。

转载请注明出处https://www.0291.com.cn/post/44565.html

相关文章

抖音怎样才能产生收益(抖音怎样才能产生收益呢)

抖音怎样才能产生收益(抖音怎样才能产生收益呢)

       大家好!今天让小编来大家介绍下关于抖音怎样才能产生收益(抖音怎样才能产生收益呢)的问题,以下是小编对此问题的归纳整理,让我们一起来看看吧。 文章目录列表: 1、 2、 3、 4、 一、抖音上发作品怎么样...

ps如何添加水印(ps水印制作教程分享)

ps如何添加水印(ps水印制作教程分享)

大家好,今天给大家分享PS给图片添加水印的方法,具体操作如下: 1.打开PS,新建一个500*500像素的画布点击创建,在上面新建一个图层输入水印内容,可任意旋转水印的角度并 隐藏背景图层,然后在编辑里打开定义图案,输入保存的名称点击确定。  ...

快手创作平台官网入口(快手mcn机构入驻详细流程)

快手创作平台官网入口(快手mcn机构入驻详细流程)

快手是中国最大的短视频平台之一,拥有数亿的活跃用户。作为自媒体平台,快手为广大的内容创作者提供了一个展示自己创作才华的平台。如果你也想在快手上发布自己的内容,建立自己的粉丝群体,那么本篇文章就是给你的一个注册教程。 第一步:下载快手APP并注册账号 首先,你需要在手机应用商店中下载快手A...

快手广告怎么开户?快手信息流广告开户流程介绍

快手广告怎么开户?快手信息流广告开户流程介绍

如果您想做快手推广,开户较好的选择就是巨宣网络!为什么呢,因为我们拥有多年的搜索和信息流、视频广告运营经验,在行业内我公司也是小有名气的,很多客户合作的比较稳定,大部分行业的客户我们都拥有头部客户,合作的企业反馈的效果都是不错的! 快手怎么开户呢?首先快手开户之前您需要准备好开户的资质,快手推...

抖音直播带货特点有哪些

抖音直播带货特点有哪些

大家经常看抖音直播的都应该知道,很多主播直播一场考验卖货很多,为什么一些大的主播都选择在抖音上直播呢?抖音直播带货特点有哪些?   日活量大、带货门槛低   想入驻抖音开直播,并不是什么难事,注册账号后,只要发布10个以上的视频,粉...

抖音点赞占手机内存吗(让抖音不占内存的方法)

抖音点赞占手机内存吗(让抖音不占内存的方法)

抖音给人们的生活带来了精彩,但是它也给我们的手机添加了不少负载。经常玩手机的用户,都会发现手机空间越来越小了,手机变得也会越来越慢了。当我们查找原因的时候,你会很惊讶地发现,抖音已经占用了手机空间的几个G、十几个G甚至更多的空间。   抖音为什么会占用手机空间这...

现在,非常期待与您的又一次邂逅

我们努力让每一部企业宣传片和抖音短视频成为商业大片