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>
繼續學習
||
<!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>