请选择
进入手机版
|
继续访问电脑版
设为首页
收藏本站
开启辅助访问
切换到宽版
登录
立即注册
快捷导航
发布信息
搜索
搜索
网站首页
自丢网
社区论坛
自丢网论坛
附件中心
源码下载
邀请码
丢币充值
本版
帖子
自丢网
»
社区论坛
›
建站程序/IT教程
›
建站/web前端教程
›
HTML5CSS3+JS实现灵动岛效果
返回列表
发新帖
HTML5CSS3+JS实现灵动岛效果
[复制链接]
857
|
0
|
2022-9-19 21:09
|
显示全部楼层
|
阅读模式
主要利用CSS3-animation + JS实现效果,只是提供思路,具体细节可以参考
HTML5CSS3+JS实现灵动岛效果
代码如下:
<!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>
复制代码
灵动岛效果
,
前端特效
回复
举报
返回列表
发新帖
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
立即注册
本版积分规则
发表回复
回帖后跳转到最后一页
admin
UID
1
贡献
387
丢币
38902
主题
4607
回帖
116
注册时间
2018-9-25
最后登录
2024-3-24
加好友
发消息
回复楼主
返回列表
源码下载
Thinkphp教程
修罗xiuno教程
Discuz教程
zzz资源/教程
织梦教程
服务器教程
数据库教程
Html/Html5教程
JavaScript教程
Css/Css3教程
建站/web前端教程
PHP教程
其他编程教程
小程序app教程
PPT模板/素材
Word简历模板/素材
Excel模板/素材
素材中心
百科知识
图文推荐
html+js实现本站已运行运营多少天代码
2024-2-8 09:19
2024年最新ThinkPHP8.x 讲义代码SQL,实战部分结合四种前端教程
2024-1-23 09:25
小学生必背古诗75首-标注-翻译-A4可打印word版本下载
2024-1-23 09:18
长截图 截动图gif制作 贴图软件免费下载
2024-1-22 10:45
D盾_防火墙 版本: v2.1.8.1最新绿色免安装版本扫木马病毒
2024-1-22 08:27
热门排行
1
修罗轻论坛程序Xiuno免费开源+收费插件模板风格大全 价值1200元 百度云网盘下载
2
仿看雪论坛模板风格 for 修罗模板 支持4.0以上版本
3
【专业商业版】积分插件 v1.25 for xiuno修罗插件
4
修罗程序添加水印插件 for xiuno插件 支持4.0以上版本
5
邀请注册、用户消费购买邀请码 for 修罗插件 支持xiuno4.0以上版本
6
分类/标签(TAG) - 增强版 v2.5 for xiuno插件 支持4.0以上版本
7
tStore积分商城插件 v1.03 for 修罗插件 xiuno4.0以上版本
8
UMEditor 百度编辑器 v2.6 for 修罗插件xiuno 支持4.0以上版本