0

コンテンツをフェードアウトしようとしsection#secondaryています。コンテンツがフェードアウトされると、親(section#secondary)はスライダーアニメーションで「shut」をアニメーション化する必要があります。

これはすべて機能していますが、期間は機能しておらず、理由がわかりません。

これが私のコードです:

HTML

<section id="secondary">
    <a href="#" class="slide_button">&laquo;</a> <!-- slide in/back button -->              
    <article>

        <h1>photos</h1>
        <div class="album_nav"><a href="#">photo 1 of 6</a> | <a href="#">create an album</a></div>
        <div class="bar">
            <p class="section_title">current image title</p>
        </div>

        <section class="image">

            <div class="links"> 
                <a class="_back album_link" href="#">« from the album: james new toy</a>
                <nav>
                    <a href="#" class="_back small_button">back</a>
                    <a href="#" class="_next small_button">next</a>
                </nav>
            </div>  

            <img src="http://localhost/~jannis/3781_doggie_wonderland/www/preview/static/images/sample-image-enlarged.jpg" width="418" height="280" alt="" />

        </section>

    </article>

    <footer>
        <embed src="http://localhost/~jannis/3781_doggie_wonderland/www/preview/static/flash/secondary-footer.swf" wmode="transparent" width="495" height="115" type="application/x-shockwave-flash" />
    </footer>

</section> <!-- close secondary -->

jQuery

// =============================
// = Close button (slide away) =
// =============================
$('a.slide_button').click(function() {
    $(this).closest('section#secondary').children('*').fadeOut('slow', function() {
        $('section#secondary').animate({'width':'0'}, 3000);
    });
});

の内容section#secondaryは可変なので、*セレクターを使用します。

何が起こるかというと、fadeOutは適切なslow速度を使用しますが、コールバックが起動するとすぐに(コンテンツがフェードアウトすると)、アニメーションの継続時間を3000ミリ秒(3秒)ではなく、数ミリ秒以内にsection#secondaryアニメーション化します。width: 0

任意のアイデアをいただければ幸いです。

PS:現時点では例を投稿することはできませんが、これはjQueryの理論の問題であるため、ここでは例は必要ないと思います。私が間違っている場合は私を訂正してください。

4

2 に答える 2

0

ここで少なくとも 1 つの潜在的な問題は、からのコールバック.fadeOut()(次に を呼び出す.animate()) が、から選択された子の数に対して複数回実行される可能性があること.children('*')です。これはおそらく、コールバックが 1 回だけ実行されるように作り直す必要があります。

于 2010-05-11T03:05:04.450 に答える
0

幅が 0 に変わってよろしいですか? 次のサンプルを実行すると、最初のコールバックが発生するまで幅が 0 ではないことがわかります。

コールバックは第 1 レベルの子ごとに 1 回、したがってこのサンプルでは 3 回発生することに注意してください。

<html>
    <head>
        <script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
        <script type="text/javascript">

            $(document).ready(function() {
                $('a.slide_button').click(function() {
                    $('div#secondary').children().fadeOut('slow',function(){
                        // this has scope of the html element
                        console.log(this);
                        console.log($(this).parent().width());
                        $(this).parent().animate({'width':'0'}, 3000, function(){
                            console.log($(this).width());
                        });
                    });
                });
            });

        </script>
    </head>
    <body>

        <div id="secondary" style="background: red;">          
            <a href="#" class="slide_button">&laquo;</a> <!-- slide in/back button -->  
            <div>

                <h1>photos</h1>
                <div class="album_nav"><a href="#">photo 1 of 6</a> | <a href="#">create an album</a></div>
                <div class="bar">
                    <p class="section_title">current image title</p>
                </div>

                <div class="image">

                    <div class="links"> 
                        <a class="_back album_link" href="#">« from the album: james new toy</a>
                        <nav>
                            <a href="#" class="_back small_button">back</a>
                            <a href="#" class="_next small_button">next</a>
                        </nav>
                    </div>  

                </div>

            </div>

            <div>
                <p>Footer</p>
            </div>

       </div>

    </body>
</html>
于 2010-05-11T03:26:47.197 に答える