CSS滤镜之blur属性

假如您用手在一幅还没干透的油画上迅速划过,画面就会变得模糊。CSS下的blur属性就会达到这种模糊的效果。
先来看一下blur属性的表达式:

filter:blur(add=add,direction,strength=strength)

我们看到blur属性有三个参数:add、direction、strength。
Add参数有两个参数值:true和false。意思是指定图片是否被改变成模糊效果。 Direction参数用来设置模糊的方向。模糊效果是按照顺时针方向进行的。其中0度代表垂直向上,每45度一个单位,默认值是向左的270度。角度方向的对应关系见下表:

Strength参数值只能使用整数来指定,它代表有多少像素的宽度将受到模糊影响。默认值是5像素。
还是看一个例子吧。

===================

 1<html>
 2<head>
 3<title>blur css</title>
 4<script>   
 5function handlechange(obj)   
 6{   
 7with(obj.filters(0))   
 8{   
 9if (strength<255)   
10{   
11strength +=2;   
12direction +=45;   
13}   
14}   
15}   
16</script>
17</head>
18<body>
19<p><img id="img1" onfilterchange="handlechange(this)" src="jsimg/1.jpg" style="filter:blur(strength=1)"/>
20</p>
21</body>
22</html>

=====================

看起来是不是有些像万花筒,在这个例子中加入了一些JavaScript的语句,代码如下:

 1<html>
 2<head>
 3<title>blur css</title>
 4<script>   
 5function handlechange(obj)   
 6//*设置一个循环函数handlechange,对象是obj*//    
 7{ with(obj.filters(0))  //*Obj的filter属性*//    
 8{ if (strength<255)  //*设置循环条件*//    
 9{ strength +=1;direction +=45;}    
10//*每循环一次strength就加1,direction加45度*//    
11}   
12}   
13</script>
14</head>
15<body>
16<p><img id="“img1”" onfilterchange="“handlechange(this)”" src="“ss01087.jpg”" style="“filter:blur(strength=1)”"/>   
17//*导入一幅图片,初始blur属性strength等于1,同时调用onfilterchange函   
18数*//    
19</p>
20</body>
21</html>

注:在javascript中blur属性是这样定义的:
[oBlurfilter=] object.Filters.blur

这个例子是Blur属性的一个比较复杂的例子,下一节我将向您介绍两个较简单的blur属性效果。

通过blur属性还可以设置页面中的字体。如果把字体的blur属性add参数值定义为1,得出来的字体效果是这样的(如下图):

怎么样,是不是有些印象派的意思,这种效果的实现代码如下:

 1<html>
 2<head>
 3<title>filter blur</title>
 4<style> //*CSS样式定义开始*//    
 5<!--   
 6div{width:200;   
 7filter:blur(add=true,direction=90,strength=25);}    
 8//*设置DIV样式,滤镜blur属性*//    
 9\-->   
10</style>
11</head>
12<body>
13<div 288”="" height:="" style="“width:702;">
14<p font-size:72;font-style:bold;color:rgb(55,72,145);”="" handwirting="" italic;="" style="“font-family:lucida">   
15LEAF</p>   
16//*定义字体名称、大小、样式、前景色*//    
17</div>
18</body>
19</html>

我们看到strength设置为25,如果把其值再改大一些,就会达到非常夸张的效果,同时把Direction参数值为180,显示效果如下图:

用blur属性设置字体可以达到很多效果,把direction和strength再做修改,还能达到多种效果,您可以自己修改试一试。

Published At
Categories with 网页设计
Tagged with
comments powered by Disqus