【问题标题】:JQuery mCustomScrollbar autoScrollOnFocusJQuery mCustomScrollbar autoScrollOnFocus
【发布时间】:2013-06-30 16:23:17
【问题描述】:

我有 reCaptcha 的联系表格并使用 jQuery mCustomScrollbar 插件。

问题:当我点击/关注 reCaptcha 字段时,页面会自动滚动到 div 的顶部。

Demo on JsffidleCode on Jsfiddle

注意:如果 mscrollbar 不能在 jsfiddle 上运行,那就是从 malihu 站点调用 js 和 css 的问题。

$(".scroller-back").mCustomScrollbar({
   advanced:{
     updateOnContentResize: true
   }           
});

使用autoScrollOnFocus: false

在具有焦点的元素上自动滚动(例如滚动条 按下 TAB 键时自动滚动以形成文本字段), 值:真、假。

$(".scroller-back").mCustomScrollbar({
   advanced:{
     autoScrollOnFocus: false,
     updateOnContentResize: true
   }           
});

它适用于所有字段焦点而不是自动滚动,如何在不使用autoScrollOnFocus: false 的情况下解决此问题?

【问题讨论】:

    标签: jquery scrollbar recaptcha mcustomscrollbar


    【解决方案1】:

    已解决

    我正在使用focus()函数和mCustomScrollbar函数scrollTo

    $("#recaptcha_response_field").focus(function() {
      $(".scroller-back").mCustomScrollbar("scrollTo",this);
    });
    

    Code on Jsffidle

    当光标聚焦在recaptcha 文本字段上时,滚动将滚动到recaptcha 文本字段所在的行(滚动到self)。但是当我们使用 tab 键时它不起作用。我已经尝试过警报

    $('#recaptcha_response_field').focus(function() {
      alert('Handler for .focus() called.');
    });
    

    更新

    我正在使用带有目标 ID 提交按钮的 scrollTo。

    var a=Recaptcha.$("recaptcha_response_field");
    
    $(a).focus(function() {
      $(".scroller-back").mCustomScrollbar("scrollTo","#submit_button");
    });
    

    Code on Jsffidle

    【讨论】:

      【解决方案2】:
      $(".scroller-back").mCustomScrollbar("scrollTo", $("#yourdiv"));
      

      【讨论】:

      • 由于这是一个非常古老的问题,并且答案在几年前就被接受了,并且有更多的上下文,我建议你删除这个答案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-15
      • 1970-01-01
      • 2017-05-08
      • 1970-01-01
      • 1970-01-01
      • 2016-06-05
      相关资源
      最近更新 更多