#不用庫 也能酷 - 玩轉 CSS & Js 特效 #HTML #CSS #JavaScript

Day24 CSS 相融黏滯效果

Date
2023.10.08
Category
網頁開發
Read Time
6 min
Word
1.7k
Last Mod
2023.10.08
課程 2023.10.08

Day24 CSS 相融黏滯效果

今天我們要來做這個紓壓的效果:

https://codepen.io/elvismao/pen/poqqoLr

成果
成果

然後你可以應用做出一些很酷的效果:

原理

原理其實很簡單。要讓兩個東西之間相連只需要模糊就會糊在一起了。

blur
blur
HTML
<div class="box">	<div class="circle-small"></div>	<div class="circle-big"></div></div>
CSS
.box {	position: relative;	height: 100vh;	background-color: #fff;}.circle-big,.circle-small {	filter: blur(10px);	border-radius: 50%;	width: 80px;	height: 80px;	background-color: red;	position: absolute;	left: 50%;	top: 50%;	transform: translate(-50%, -50%);}.circle-big {	width: 100px;	height: 100px;	background-color: black;	transform: translate(0, -50%);}

然後增加對比讓中間模糊的部分更明顯:

增加對比讓中間模糊的部分更明顯
增加對比讓中間模糊的部分更明顯
CSS
.box {	position: relative;	height: 100vh;	background-color: #fff;	filter: contrast(20);}

最後讓它動起來

CSS
.box {	position: relative;	height: 500px;	filter: contrast(20);	background-color: #fff;}.circle-big,.circle-small {	border-radius: 50%;	filter: blur(10px);	animation: 2s infinite move alternate;	width: 80px;	height: 80px;	background-color: red;	transform: translatex(20px);	position: absolute;	left: 50%;	top: 50%;	transform: translate(-50%, -50%);}.circle-big {	width: 100px;	height: 100px;	background-color: black;	animation-delay: -2s;}@keyframes move {	from {		transform: translate(calc(-50% + 100px), -50%);	}	to {		transform: translate(calc(-50% - 100px), -50%);	}}

好,結束。

成果
成果

你可以自由應用在你的網頁上。以下是幾個範例:

來源:https://codepen.io/Chokcoco

連結:https://codepen.io/YusukeNakaya/pen/vvEqVx

這個效果明天會使用到,你可以來猜猜看。我剩下六天了,接下來原則上都是蠻重要的內容,要來完成一些很常見的版面和許多人習慣直接套庫的東西。以上就是我今天的分享,歡迎在 InstagramGoogle 新聞追蹤毛哥EM資訊密技,也歡迎訂閱我新開的YouTube 頻道:網棧

我是毛哥EM,讓我們明天再見。

About me

毛哥EM

這裡是毛哥EM,一隻全端開發龍還有英文辯士。
熱愛開源、音樂、設計、獸迷文化,專研人機互動與人工智慧。

本部落格皆屬原創文章,採 CC BY-SA 4.0 授權,
轉載請註明來自毛哥EM資訊密技。
這篇文章對你有幫助嗎? 考慮幫我買瓶 Red Bull?

毛哥EM 角色插圖

Comments

留言區