<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS filter模糊效果演示</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background-color: #f5f7fa;
padding: 40px;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
}
h1 {
color: #333;
margin-bottom: 30px;
text-align: center;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 30px;
max-width: 1200px;
margin-bottom: 40px;
}
.image-box {
width: 300px;
background: white;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
transition: transform 0.3s;
}
.image-box:hover {
transform: translateY(-5px);
}
.image-container {
height: 200px;
overflow: hidden;
}
.image-container img {
width: 100%;
height: 100%;
object-fit: cover;
transition: filter 0.5s ease;
}
.controls {
padding: 15px;
background: #fff;
}
.control-group {
margin-bottom: 10px;
}
label {
display: block;
margin-bottom: 5px;
font-size: 14px;
color: #555;
}
input[type="range"] {
width: 100%;
height: 6px;
-webkit-appearance: none;
background: #e0e0e0;
border-radius: 3px;
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 16px;
height: 16px;
background: #4776E6;
border-radius: 50%;
cursor: pointer;
}
.blur-value {
font-size: 12px;
color: #888;
text-align: right;
}
.website-link {
display: inline-block;
margin-top: 30px;
padding: 10px 20px;
background: linear-gradient(to right, #4776E6, #8E54E9);
color: white;
text-decoration: none;
border-radius: 30px;
font-size: 14px;
transition: all 0.3s;
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}
.website-link:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}
.code-example {
background: #282c34;
color: #abb2bf;
padding: 20px;
border-radius: 6px;
font-family: 'Courier New', monospace;
margin: 30px 0;
width: 100%;
max-width: 800px;
overflow-x: auto;
}
.code-example .comment {
color: #5c6370;
font-style: italic;
}
.code-example .property {
color: #56b6c2;
}
.code-example .value {
color: #98c379;
}
</style>
</head>
<body>
<h1>CSS filter 图片模糊效果演示</h1>
<div class="container">
<div class="image-box">
<div class="image-container">
<img id="blurImage1" src="https://picsum.photos/600/400?random=1" alt="示例图片1">
</div>
<div class="controls">
<div class="control-group">
<label for="blurRange1">模糊程度 (blur)</label>
<input
type="range"
id="blurRange1"
min="0"
max="10"
step="0.5"
value="0"
oninput="updateBlur('blurImage1', this.value)"
>
<div class="blur-value" id="blurValue1">0px</div>
</div>
</div>
</div>
<div class="image-box">
<div class="image-container">
<img id="blurImage2" src="https://picsum.photos/600/400?random=2" alt="示例图片2">
</div>
<div class="controls">
<div class="control-group">
<label for="blurRange2">模糊程度 (blur)</label>
<input
type="range"
id="blurRange2"
min="0"
max="10"
step="0.5"
value="0"
oninput="updateBlur('blurImage2', this.value)"
>
<div class="blur-value" id="blurValue2">0px</div>
</div>
</div>
</div>
</div>
<div class="code-example">
<span class="comment">/* CSS filter 模糊效果代码示例 */</span><br>
.blur-image {<br>
<span class="property">filter</span>: <span class="value">blur(3px)</span>; <span class="comment">/* 设置3像素模糊效果 */</span><br>
}<br><br>
<span class="comment">/* 动态修改模糊度 */</span><br>
document.getElementById('image').style.filter = <span class="value">'blur(5px)'</span>;
</div>
<script>
function updateBlur(imageId, value) {
const image = document.getElementById(imageId);
const valueDisplay = document.getElementById('blurValue' + imageId.slice(-1));
// 应用模糊滤镜
image.style.filter = `blur(${value}px)`;
// 更新显示的值
valueDisplay.textContent = `${value}px`;
}
</script>
</body>
</html>
CSS filter模糊效果演示
于 2025-04-24 15:08:44 首次发布
709

被折叠的 条评论
为什么被折叠?



