2011-08-01 29 views

回答

1

爲了讓它反彈你缺少兩件事我認爲:

1)你需要加載jQuery UI。

2)把動畫效果後反彈效果:

$('#test').click(function() { 
    var $marginLefty = $('.left'); 
    $marginLefty.animate({ 
     marginLeft: parseInt($marginLefty.css('marginLeft'),10) == 0 ? 
     $marginLefty.outerWidth() : 
     0 
    }).effect("bounce", { times:5 }, 300); 
    }); 

更新小提琴:http://jsfiddle.net/nicolapeluchetti/E6cUF/4/

+0

謝謝,看到編輯過的第一篇文章! – Writecoder

+0

這樣的事情? http://jsfiddle.net/nicolapeluchetti/RBD3K/1/ –

+0

完全是這樣,但在左側,它們之間有一點空間,並在頁面加載後。 我自己試了一下,加載後現在反彈,但灰色的div必須在左邊,灰色和綠色的div之間有10px的空格http://jsfiddle.net/RBD3K/5/非常感謝! – Writecoder

0

試試這個。不知道這是你想要的。

$('#test').click(function() { 
    var $marginLefty = $('.left'); 
    var $marginRight = $('.right'); 
    $marginLefty.animate({ 
     marginLeft: 0 
    },{ duration: 200, queue: false }); 
    $marginRight.animate({ 
     marginLeft: 100 
    },{ duration: 200, queue: false }); 
    }); 

更新:從您的更新小提琴,爲.right position :absolute;z-index:1000添加爲CSS

http://jsfiddle.net/E6cUF/11/