Search
  1. fadeIn(speed[, callback])〔要素をフェードイン〕
  2. fadeOut(speed[, callback])〔要素をフェードアウト〕
  3. fadeTo(speed, opacity[, callback])〔透明度を指定して要素をフェード〕

fadeIn(speed[, callback])
要素をフェードイン

2009/2/27

fadeIn(speed[, callback]) 戻り値:jQuery

マッチした要素を透明度を調整しながらフェードインします。 オプションの第2引数callbackを指定した場合は、要素のアニメーション完了時に指定したコールバック関数を実行します。

マッチした各要素の透明度は、アニメーションで調整されます。 そのため、マッチした要素には、スタイルシートで高さと幅の指定をしておく必要があります。

  • 第1引数sppedには、要素をフェードインする時のアニメーション速度を指定します。 数値(ミリ秒)あるいは文字列を指定可能です。 数値の場合、例えば3秒なら「3000」を指定します。 文字列の場合、「slow」(ゆっくり)、「def」(デフォルト)、「fast」(速く)のあらかじめ決められた速度のいずれかを指定します。 jQuery v1.2.6からは、「normal」またはその他の文字列は「def」(400ミリ秒)と同じです。

  • オプションの第2引数callbackには、アニメーションが完了した時に実行する関数を指定します。 関数が実行されるのは各要素に対して1度だけです。

    function callback(){
        this; /* DOM要素 */
    }
設置イメージ設置イメージ
fadeIn()の使用例サンプルを見る
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="Content-Language" content="ja" />
        <meta http-equiv="Content-Script-Type" content="text/javascript" />
        <meta http-equiv="Content-Style-Type" content="text/css" />
        <meta http-equiv="imagetoolbar" content="no" />
        <title>エフェクト操作:フェーディング:FadeIn()の使用例 | jQuery</title>
        <link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
        <script type="text/javascript">
            $(function(){
                $("#btn_slow").click(function(){
                    $("#sample_slow img:hidden:first").fadeIn("slow");
                });
                $("#btn_normal").click(function(){
                    $("#sample_normal img:hidden:first").fadeIn("normal");
                });
                $("#btn_fast").click(function(){
                    $("#sample_fast img:hidden:first").fadeIn("fast");
                });
            });
        </script>
        <style type="text/css">
            td { text-align:center; }
            #sample_slow, #sample_normal, #sample_fast { width:240px; height:180px; background-color:#e5d19e; }
            #sample_slow img, #sample_normal img, #sample_fast img { display:none; }
        </style>
    </head>
    <body>
        <div id="wrap">
            <h1>エフェクト操作:フェーディング:FadeIn()の使用例 | jQuery</h1>
<!-- CODE -->
            <table>
                <tr>
                    <td><button id="btn_slow">フェードイン(ゆっくり)</button></td>
                    <td><button id="btn_normal">フェードイン(普通)</button></td>
                    <td><button id="btn_fast">フェードイン(速く)</button></td>
                </tr>
                <tr>
                    <td><div id="sample_slow"><img src="http://farm4.static.flickr.com/3222/2974008614_736e2d5b50_m.jpg" width="240" height="180" alt="くまさんケーキ" /></div></td>
                    <td><div id="sample_normal"><img src="http://farm4.static.flickr.com/3222/2974008614_736e2d5b50_m.jpg" width="240" height="180" alt="くまさんケーキ" /></div></td>
                    <td><div id="sample_fast"><img src="http://farm4.static.flickr.com/3222/2974008614_736e2d5b50_m.jpg" width="240" height="180" alt="くまさんケーキ" /></div></td>
                </tr>
            </table>
<!-- / CODE -->
        </div>
    </body>
</html>

例:写真をフェードイン・アウト効果を付けてスライドショー

参照:Simplest jQuery Slideshow

指定した要素内にあるimg要素を順番にフェード効果を付けてスライドショーさせるシンプルなスライドショーを作成する方法が掲載されています。SetIntervalを使用して、一定秒数間隔でフェードアニメーションを付けて次の画像に切り替えています。

fadeIn()の使用例サンプルを見る
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="Content-Language" content="ja" />
        <meta http-equiv="Content-Script-Type" content="text/javascript" />
        <meta http-equiv="Content-Style-Type" content="text/css" />
        <meta http-equiv="imagetoolbar" content="no" />
        <title>エフェクト操作:フェーディング:FadeIn()の使用例 | jQuery</title>
        <link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
        <script type="text/javascript">
            $(function(){
                $('.fadein img:gt(0)').hide();
                setInterval(function(){$('.fadein :first-child').fadeOut("slow").next('img').fadeIn("slow").end().appendTo('.fadein');}, 3000);
            });
        </script>
        <style type="text/css">
            .fadein { position:relative; width:240px; height:240px; }
            .fadein img { position:absolute; left:0; top:0; }
        </style>
    </head>
    <body>
        <div id="wrap">
            <h1>エフェクト操作:フェーディング:FadeIn()の使用例 | jQuery</h1>
            <p>参照:<a href="http://snook.ca/technical/fade/fade.html" target="_blank">Simplest jQuery Slideshow</a></p>
            <p>指定した要素内にあるimg要素を順番にフェード効果を付けてスライドショーさせるシンプルなスライドショーを作成する方法が掲載されています。SetIntervalを使用して、一定秒数間隔でフェードアニメーションを付けて次の画像に切り替えています。</p>
<!-- CODE -->
            <div class="fadein"> 
                <img src="http://farm2.static.flickr.com/1339/5153283180_66ae05b976_m.jpg" />
                <img src="http://farm2.static.flickr.com/1060/5152662415_4083803c89_m.jpg" />
                <img src="http://farm5.static.flickr.com/4153/5153266560_a8d45226f1_m.jpg" />
            </div>
<!-- / CODE -->
        </div>
    </body>
</html>

fadeOut(speed[, callback])
要素をフェードアウト

2009/2/27

fadeOut(speed[, callback]) 戻り値:jQuery

マッチした要素を透明度が0になるまで調整しながらフェードアウトします。 オプションの第2引数callbackを指定した場合は、要素のアニメーション完了時に指定したコールバック関数を実行します。

マッチした各要素の透明度は、アニメーションで調整されます。 そのため、マッチした要素には、スタイルシートで高さと幅の指定をしておく必要があります。

  • 第1引数sppedには、要素をフェードアウトする時のアニメーション速度を指定します。 数値(ミリ秒)あるいは文字列を指定可能です。 数値の場合、例えば3秒なら「3000」を指定します。 文字列の場合、「slow」(ゆっくり)、「normal」(通常)、「fast」(速く)のあらかじめ決められた速度のいずれかを指定します。

  • オプションの第2引数callbackには、アニメーションが完了した時に実行する関数を指定します。 関数が実行されるのは各要素に対して1度だけです。

    function callback(){
        this; /* DOM要素 */
    }
設置イメージ設置イメージ
fadeOut()の使用例サンプルを見る
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="Content-Language" content="ja" />
        <meta http-equiv="Content-Script-Type" content="text/javascript" />
        <meta http-equiv="Content-Style-Type" content="text/css" />
        <meta http-equiv="imagetoolbar" content="no" />
        <title>エフェクト操作:フェーディング:FadeOut()の使用例 | jQuery</title>
        <link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
        <script type="text/javascript">
            $(function(){
                $("#btn_slow").click(function(){
                    $("#sample_slow img:visible").fadeOut("slow");
                });
                $("#btn_normal").click(function(){
                    $("#sample_normal img:visible").fadeOut("normal");
                });
                $("#btn_fast").click(function(){
                    $("#sample_fast img:visible").fadeOut("fast");
                });
            });
        </script>
        <style type="text/css">
            td { text-align:center; }
            #sample_slow, #sample_normal, #sample_fast { width:240px; height:180px; background-color:#e5d19e; }
        </style>
    </head>
    <body>
        <div id="wrap">
            <h1>エフェクト操作:フェーディング:FadeOut()の使用例 | jQuery</h1>
<!-- CODE -->
            <table>
                <tr>
                    <td><button id="btn_slow">フェードアウト(ゆっくり)</button></td>
                    <td><button id="btn_normal">フェードアウト(普通)</button></td>
                    <td><button id="btn_fast">フェードアウト(速く)</button></td>
                </tr>
                <tr>
                    <td><div id="sample_slow"><img src="http://farm4.static.flickr.com/3222/2974008614_736e2d5b50_m.jpg" width="240" height="180" alt="くまさんケーキ" /></div></td>
                    <td><div id="sample_normal"><img src="http://farm4.static.flickr.com/3222/2974008614_736e2d5b50_m.jpg" width="240" height="180" alt="くまさんケーキ" /></div></td>
                    <td><div id="sample_fast"><img src="http://farm4.static.flickr.com/3222/2974008614_736e2d5b50_m.jpg" width="240" height="180" alt="くまさんケーキ" /></div></td>
                </tr>
            </table>
<!-- / CODE -->
        </div>
    </body>
</html>

fadeTo(speed, opacity[, callback])
透明度を指定して要素をフェード

2009/2/27

fadeTo(speed, opacity[, callback]) 戻り値:jQuery

マッチした各要素を指定した透明度になるまでフェードします。 オプションの第2引数callbackを指定した場合は、要素のアニメーション完了時に指定したコールバック関数を実行します。

マッチした各要素の透明度は、アニメーションで調整されます。 そのため、マッチした要素には、スタイルシートで高さと幅の指定をしておく必要があります。

  • 第1引数sppedには、アニメーション速度を指定します。 数値(ミリ秒)あるいは文字列を指定可能です。 数値の場合、例えば3秒なら「3000」を指定します。 文字列の場合、「slow」(ゆっくり)、「normal」(通常)、「fast」(速く)のあらかじめ決められた速度のいずれかを指定します。

  • 第2引数opacityには、要素の透明度を指定します。 0~1までの数値を指定可能です。

  • オプションの第2引数callbackには、アニメーションが完了した時に実行する関数を指定します。 関数が実行されるのは各要素に対して1度だけです。

    function callback(){
        this; /* DOM要素 */
    }
設置イメージ設置イメージ
fadeToの使用例サンプルを見る
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="Content-Language" content="ja" />
        <meta http-equiv="Content-Script-Type" content="text/javascript" />
        <meta http-equiv="Content-Style-Type" content="text/css" />
        <meta http-equiv="imagetoolbar" content="no" />
        <title>エフェクト操作:フェーディング:FadeTo()の使用例 | jQuery</title>
        <link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
        <script type="text/javascript">
            $(function(){
                $("#btn_fadeto_0").click(function(){
                    $("#sample img").fadeTo("slow",0);
                });
                $("#btn_fadeto_033").click(function(){
                    $("#sample img").fadeTo("slow",0.33);
                });
                $("#btn_fadeto_05").click(function(){
                    $("#sample img").fadeTo("slow",0.5);
                });
                $("#btn_fadeto_1").click(function(){
                    $("#sample img").fadeTo("slow", 1);
                });
            });
        </script>
        <style type="text/css">
            #content { width:400px; text-align:center; }
            #sample { margin:10px auto; width:320px; height:240px; background-color:#E5D19E; }
        </style>
    </head>
    <body>
        <div id="wrap">
            <h1>エフェクト操作:フェーディング:FadeTo()の使用例 | jQuery</h1>
<!-- CODE -->
            <div id="content">
                <p>▼ボタンをクリックすると、指定した透明度まで要素をフェードします。</p>
                <div id="sample"><img src="http://farm4.static.flickr.com/3222/2974008614_736e2d5b50.jpg" width="320" height="240" alt="くまさんケーキ" /></div>
                <p>
                    <input type="button" id="btn_fadeto_0" value="fadeTo 0" />
                    <input type="button" id="btn_fadeto_033" value="fadeTo 0.33" />
                    <input type="button" id="btn_fadeto_05" value="fadeTo 0.5" />
                    <input type="button" id="btn_fadeto_1" value="fadeTo 1" />
                </p>
            </div>
<!-- / CODE -->
        </div>
    </body>
</html>

関連コンテンツ

Q. このサイトの情報はお役に立ちましたでしょうか?

投票する 投票結果を見る

管理人に【web拍手】を送るweb拍手(1行メッセージも送れます♪)

pagetop

polarized women