如何将页面动画到另一个位置后自动将页面滚动到<div>元素?</div>

时间:2012-05-11 12:51:36

标签: jquery html css animation scroll

我有这个代码,我不知道如何自动滚动到球的移动位置。球从屏幕移出页面。

代码:

jQuery(document).ready(function($) {
$(".scroll").click(function(event){     
    event.preventDefault();
    $('html,body').animate({scrollTop:$(this.hash).offset().top}, 500);
}); 
});

$(function() {
    $( "#ball" ).draggable({ containment: "#containment-wrapper", scroll: false, revert: "invalid" });
    $( "#ball2" ).draggable({ containment: "#containment-wrapper", scroll: false, revert: "invalid" });
$( "#droppable" ).droppable({
        activeClass: "ui-state-hover",
        hoverClass: "ui-state-active",
        drop: function( event, ui ) {
            $("#ball2").animate({left: '-=100', top: '-=250'}, 300);
            $( this )
                .addClass( "ui-state-highlight" )
                .find( "p" )
                    .html( "ball runs up" );
        }           
});
});

1 个答案:

答案 0 :(得分:1)

你能不能只使用scrollIntoView()

http://www.quirksmode.org/dom/tests/scrollintoview.html