jQuery颜色渐变动画

颜色渐变动画

fadeIn(spend,[callback]):不透明度的变化来实现所有匹配元素的淡入效果(显示)

fadeOut(spend,[callback]):通过不透明度的变化来实现所有匹配的淡出效果(隐藏)

fadeTo(spend,opacity,[callback]):把所以匹配元素的透明度以渐进方式调整到指定的不透明度

fadeToggle(spend,[callback]):通过不透明度的变化来开关所有匹配元素的淡入和淡出效果

颜色渐变动画效果

<!DOCTYPE html>
<html>
    <head>
        <title>php.cn</title>
        <meta charset="utf-8" />
        <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
        <script>
        function f1(){
            //隐藏 
            $('div').fadeOut(3000);
        }
        function f2(){
            //显示 show
            $('div').fadeIn(3000);
        }
        function f3(){
            $('div').fadeToggle(3000);
        }
        </script>
        <style type="text/css">
        div {width:300px; height:200px; background-color:blue;}
        </style>
    </head>
    <body>
        <div></div>
        <input type="button" value="隐藏" onclick="f1()" />
        <input type="button" value="显示" onclick="f2()" />
        <input type="button" value="开关" onclick="f3()" />
    </body>
</html>

设置指定的透明度

<!DOCTYPE html>
<html>
    <head>
        <title>php.cn</title>
        <meta charset="utf-8" />
        <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
        <script>
        function f1(){
            //fadeTo(speed, opacity 透多0-1透少, [callback])
            $('#two').fadeTo(0,0.3);
        }
        </script>
        <style type="text/css">
        #one {width:300px; height:200px; background-color:yellow; 
            font-size:35px; font-weight:bold;
            position:absolute; left:40px; top:40px;
        }
        #two {width:300px; height:200px; background-color:green; 
            font-size:35px; font-weight:bold;
             position:absolute; left:60px; top:60px;
        }
        </style>
    </head>
    <body>
        <div id="one">this is one div</div>
        <div id="two">this is two div</div>
        <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
        <input type="button" value="设置" onclick="f1()" />
    </body>
</html>
Weiter lernen
||
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!DOCTYPE html>
<html>
<head>
<title>php.cn</title>
<meta charset="utf-8" />
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
function f1(){
//
$('div').fadeOut(3000);
}
function f2(){
// show
$('div').fadeIn(3000);
}
function f3(){
$('div').fadeToggle(3000);
}
</script>
<style type="text/css">
div {width:300px; height:200px; background-color:blue;}
</style>
</head>
<body>
<div></div>
<input type="button" value="" onclick="f1()" />
<input type="button" value="" onclick="f2()" />
<input type="button" value="" onclick="f3()" />
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
einreichenCode zurücksetzen
图片放大关闭