CSS filter模糊效果演示

<!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>
        &nbsp;&nbsp;&nbsp;&nbsp;<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>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值