Jquery 当单击所选容器时,滚动并设置modal body顶部的div

Jquery 当单击所选容器时,滚动并设置modal body顶部的div,jquery,html,twitter-bootstrap,bootstrap-modal,jquery-chosen,Jquery,Html,Twitter Bootstrap,Bootstrap Modal,Jquery Chosen,我在modal中有一个表单,我用选中的jquery格式化我的选择框 我想在单击所选容器时将div滚动到模态体的顶部 当单击所选容器时,我希望jquery提供这种类型的滚动 我试着这样做: //$(document).on('click','.search-field',function(){ $(document).on('click','.chosen-choices',function(){ console.log("ok"); // $(this).animate({

我在modal中有一个表单,我用选中的jquery格式化我的选择框

我想在单击所选容器时将div滚动到模态体的顶部

当单击所选容器时,我希望jquery提供这种类型的滚动

我试着这样做:

//$(document).on('click','.search-field',function(){
$(document).on('click','.chosen-choices',function(){
    console.log("ok");
    // $(this).animate({scrollTop: $(this).closest('.modal-body').offset().top},'slow');
    // $('body').animate({scrollTop: $(this).closest('.modal-body').offset().top},'slow');
    $('.modal-body').animate({scrollTop: $(this).closest('.modal-body').offset().top},'slow');
    // $(this).closest('.chosen-container').animate({scrollTop: $(this).closest('.modal-body').offset().top},'slow');
    // $(this).scrollTop(0);
});
如果我点击项目经理选择框,它应该固定在顶部,如果我点击分包商,它应该固定在顶部。


请帮我做这个。

试试这个。scrollIntoView({behavior:'smooth'});很抱歉不work@JazzCat..I还提供小提琴。你能检查一下有什么问题吗?当我点击项目经理选择框时,它是向下滚动而不是向上滚动的。谢谢..最后点击它solved@JazzCatIt滚动有点快我怎样才能使它平滑滚动..?我能在顶部为show label留出一些空间吗?@JazzCatTry this.scrollIntoView({behavior:'smooth');很抱歉不work@JazzCat..I还提供小提琴。你能检查一下有什么问题吗?当我点击项目经理选择框时,它是向下滚动而不是向上滚动的。谢谢..最后点击它solved@JazzCatIt滚动有点快我怎样才能使它平滑滚动..我能在顶部留一些空间给show label吗?@JazzCat