2009-05-03 14 views
0

アニメーションプラグインで何らかのバウンス効果を持たせたいのですが、動作しません。コールバックはまったく呼び出されません。jQuery:ヘルプが必要です。アニメートのコールバック機能が動作しません。

$(function() { 
    var offset = $("#first").offset(); 
    var position = $(window).scrollTop(); 
    $(window).scroll(function() { 
     var scroll = $(window).scrollTop(); 
     if (scroll>position) { 
     $("body") 
      .animate({ 
      scrollTop: offset.top + $("#first").innerHeight() + 150 
      }, 
      1000, 
      "easeInOutQuart", 
      function() { 
      $("body").animate({ 
       scrollTop: offset.top - 150 
      }, 
      1000, 
      "easeOutBounce" 
      ) 
      }) 
     } 
    }) 
    }) 

わかりました...ここで私はあなたが素晴らしい働いている理由を知らない..しかし、鉱山はありません.. $ ..です私のHTMLコードです(「HTML」)ISN 「Tが働いたが、あなたが正常に動作します。..

<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head> 
<title>Bounce Test Pad</title> 
<link rel=stylesheet href="index.css" type= "text/css" /> 
<script type="text/javascript" src ="jquery-1.3.2.js"></script> 
<script type = "text/javascript" src="jquery.easing.1.3.js"></script> 
</head> 
<body> 
    <img id="lightbulb" src = "img/veioza.png"> 
    <div id="wrapper"> 
     <img id="first" class="images" src="img/nike.jpg" /> 
     <img id ="second" class = "images" src="img/golden.jpg" /> 
     <img id = "third" class ="images" src ="img/a.jpg" /> 
    </div> 
<script type="text/javascript"> 
    $(window).resize(function() { 
     centerIt(); 
    }); 
    $(function() { 
     centerIt(); 
    }) 
    function centerIt() { 
     var viewportWidthSize = window.innerWidth; 
     var pixels = (viewportWidthSize/2) - $("#first").width()/2; 
     $("#wrapper img").css("left", pixels); 
    }; 


    $(function() { 
     var offset = $("#first").offset(); 
     var prevpos = $(window).scrollTop(); 
     var animating = false; 
     $(window).scroll(function() { 
      var curpos = $(window).scrollTop(); 
      if (curpos>prevpos && !animating) { 
       $('html').animate(
         {scrollTop: offset.top + $("#first").height()}, 
         1000, 
         "easeInOutQuart" 
        ) 
      } 
      animating = true; 
     }) 
    }) 
</script> 
</body> 
</html> 
+0

アラートやconsole.logを入れて呼び出されないことを確認してください。 –

+0

こんにちはPim、 コールバック関数にアラートを入れてみました。アラートはノンストップと呼ばれていました。それはちょうど警告非停止をポップアップ –

答えて

3

スクロールイベントを発生させるアニメーションについては、AnhTuが正しいです。

var status = $('#status'); 
var offset = $("#downcontent").offset(); 
var height = $("#downcontent").height(); 
var animating = false; 
var prevpos = $(window).scrollTop(); 

$(window).scroll(function(){ 
    var curpos = $(window).scrollTop(); 
    if (curpos > prevpos && !animating) { 
    $('html').animate(
     {scrollTop: offset.top + height}, 
     1000, 
     "easeInOutQuart", 
     function(){ 
     $('html').animate(
      {scrollTop: offset.top}, 
      1000, 
      "easeOutBounce", 
      function(){ 
      animating = false; 
      status.html('Both animations finished.<br />'); 
      } 
     ); 
     status.html('First animation finished.<br />Second animation started<br />'); 
     } 
    ); 
    animating = true; 
    status.html('First animation started<br />'); 
    } 
    prevpos = curpos; 
}); 

編集:あなたはアニメーションがまだ発生している間に再アニメーションを防ぐためにコードを追加する必要が

http://jsbin.com/aledehttp://jsbin.com/alede/editあなたがここにデモを編集することができます。)

はここに固定されたデモです

もう少しあなたのHTMLコードでデモを作成しました。 JavaScriptを少し修正し、いくつかのCSSルールを追加しました:http://jsbin.com/oqapa

+0

ありがとう、私はそれを試みたが、$( "HTML")は動作していません。しかし、ヒントをありがとう。私は私の問題を解決するためにそれを使用することができます –

+0

あなたは大歓迎です。より多くのヘルプが必要な場合は、HTMLコードを表示する必要があります。 – brianpeiris

+0

私は愚かな質問をしたい。 $( 'html')コマンドはオンラインモードでのみ動作しますか?ローカルディレクトリでは動作しませんか?私は同じコードを持っていると信じていますが、私のローカルディレクトリでは動作していません。 –

0

は、コールバック

if (scroll>position) { 
    $("body") 
     .animate({ 
     scrollTop: offset.top + $("#first").innerHeight() + 150 
     },1000,"easeInOutQuart") 
     .animate({ 
     scrollTop: offset.top - 150 
     },1000,"easeOutBounce") 
    }) 
} 

を使用せずにそれを行うが、私は、あなたが他のイベントにバインドするHAVAと思います。ボディをアニメートすると、イベントウィンドウが表示されることがあります。スクロール

関連する問題