1

我有这段代码,但我不知道如何自动滚动到球的移动位置。球移出屏幕,向上移动。

编码:

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" );
        }           
});
});
4

1 回答 1

1

你不能用scrollIntoView()吗?

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

于 2012-05-11T12:55:06.837 回答