在反弹之前将div移动指定的距离

时间:2012-09-22 22:35:20

标签: jquery html

我有一个div在弹跳之前从上到下移动,我需要让移动的距离更大。我的实际代码是:

HTML:

<div id=popup>
    <p>Please, choose what type of puzzle you'd like to play</p>
</div>

jQuery的:

       $(document).ready(function(){    
           $('#popup').show('bounce', { times:3 }, 300);
            });

我试图添加距离参数,但它没有做我需要的。

       $(document).ready(function(){    
           $('#popup').show('bounce', { times:3 , distance: 200 }, 300);
        });//No effect what ever value i give to the `distance` argument.

您可以看到the demo我正在关注。我需要将它移动到页面的中心(从顶部到中心)才会被弹回。提前完成。

2 个答案:

答案 0 :(得分:1)

设置distancedirection选项应该有效:

$('#bounce').show("bounce", {
    times: 3,
        direction: "down",
        distance: $(window).height()/2
}, 300);

请参阅演示here

答案 1 :(得分:0)

你问的问题并不是很清楚......我认为这应该有所帮助:

的Javascript

$('#popup').animate({
    top: (($(window).height()/2) - ($('#popup').outerHeight()/2)
)}, 2000, 'easeOutBounce');

可以找到缓和功能HERE