2017-10-06 8 views
1

マークされた行以外はすべて動作します。行がコメントされた行に置き換えられた場合、それは機能します。どんな助け?クリア間隔とアニメーションが機能しない

var goev = setInterval(fgoev, 2000); 
 

 
function fgoev() { 
 
    $('#eventwrap').animate({ 
 
    bottom: 0 
 
    }, 900).delay(5000).animate({ 
 
    bottom: -10 
 
    }, 100).animate({ 
 
    bottom: 0 
 
    }, 100).animate({ 
 
    bottom: -10 
 
    }, 100).animate({ 
 
    bottom: 0 
 
    }, 100); 
 
} 
 

 
$('#evclose').click(function() { 
 
    clearInterval(goev); 
 
    $('#eventwrap').animate({ 
 
    bottom: -125 
 
    }, 900); // doesn't work 
 
    //$('#eventwrap').hide(); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id='eventwrap'> 
 
    <div id='evclose'>X</div> 
 
    <a href='event.php' target='_blank' id='evinside'> 
 
    <div id='evmore'>MORE</div> 
 
    <div id='evtitleleft'>Days</div> 
 
    <div id='evtitleright'>Hours</div> 
 
    <div class='clear'></div> 
 
    <div id='evdays'> 
 
     <?php echo $diffa; ?> 
 
    </div> 
 
    <div id='evhours'> 
 
     <?php echo $diffb ?> 
 
    </div> 
 
    <div class='clear'></div> 
 
    </a> 
 
</div>

+1

どのように動作しませんか?アニメーションが全くない、または間違った位置にいるなどの理由があります。なぜ、明確な間隔が機能しないのですか?あなたの関数とinterval id変数に同じ名前が付いていることに気付きました。それをするのは良い考えではないかもしれません。 – xander

+0

@xander、 'うまく行かない 'とは何も意味しません。 – bonaca

+0

@xander、関数名を変更しました - 成功なし – bonaca

答えて

1

あなたは#evcloseイベントハンドラに新しい下の位置を設定する前に#eventwrap要素上にキューイングされているすべてのアニメーションをクリアする必要があるため問題があります。あなたがstop(true)を使用することができません、このようにするには、次の

var goev = setInterval(fgoev, 2000); 
 

 
function fgoev() { 
 
    $('#eventwrap').animate({ bottom: 0 }, 900).delay(5000) 
 
    .animate({ bottom: -10 }, 100) 
 
    .animate({ bottom: 0 }, 100) 
 
    .animate({ bottom: -10 }, 100) 
 
    .animate({ bottom: 0 }, 100); 
 
} 
 

 
$('#evclose').click(function() { 
 
    clearInterval(goev); 
 
    $('#eventwrap').stop(true, true).animate({ 
 
    bottom: -125 
 
    }, 900); 
 
});
#eventwrap { position: absolute; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id='eventwrap'> 
 
    <div id='evclose'>X</div> 
 
    <a href='event.php' target='_blank' id='evinside'> 
 
    <div id='evmore'>MORE</div> 
 
    <div id='evtitleleft'>Days</div> 
 
    <div id='evtitleright'>Hours</div> 
 
    <div class='clear'></div> 
 
    <div id='evdays'> 
 
     <?php echo $diffa; ?> 
 
    </div> 
 
    <div id='evhours'> 
 
     <?php echo $diffb ?> 
 
    </div> 
 
    <div class='clear'></div> 
 
    </a> 
 
</div>

私はあなたの代わりに不格好と遅いJSアニメーションの#eventwrapperを移動するためにCSSのキーフレームアニメーションを使用することにして見ていることも示唆していますjQueryが提供するメソッド。

+0

今はうまくいくようです。どうもありがとう。あなたは私に例を与えることができますか、またはcssキーフレームアニメーション、plsへの関連リンク? – bonaca

+0

確かに、ここに行く:https://developer.mozilla.org/en-US/docs/Web/CSS/%40keyframes –

+0

しかし、実行することは可能ですか?ご覧のとおり、divをクリックしてこのアニメーションを停止する必要がありますか? – bonaca

関連する問題