我有这个代码,我不知道如何自动滚动到球的移动位置。球从屏幕移出页面。
代码:
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" );
}
});
});
答案 0 :(得分:1)
你能不能只使用scrollIntoView()
?