JQuery mCustomScrollbar autoScrollOnFocus

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17392417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:57:45  来源:igfitidea点击:

JQuery mCustomScrollbar autoScrollOnFocus

jqueryscrollbarrecaptchamcustomscrollbar

提问by rails_id

I have contact form with reCaptcha and using jQuery mCustomScrollbar plugin.

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

Problem : When I click on / focus on reCaptcha field, the page scrolls automatically to top of the div.

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

See Demo on Jsffidle, Code on Jsfiddle

演示上Jsffidle守则的jsfiddle

note : if mscrollbar isn't working on jsfiddle, that is issue calling js and css from malihu site.

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

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

Using autoScrollOnFocus: false

使用 autoScrollOnFocus: false

Auto-scrolling on elements that have focus (e.g. scrollbar automatically scrolls-to form textfields when the TAB key is pressed), values: true, false.

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

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

It's working for all fields focus not auto scroll, how can I fix this issue without using autoScrollOnFocus: false?

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

采纳答案by rails_id

Solved

解决了

I'm using focus()function and mCustomScrollbar function scrollTo

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

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

Code on Jsffidle

Code on Jsffidle

When the cursor has focus on recaptcha text field, the scroll will scrolling to on a line with recaptcha text field (scroll to self). But it's doesn't work when we use the tab key. I have tried with alert

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

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

Updated

更新

I'm using scrollTo with target id's submit button.

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

var a=Recaptcha.$("recaptcha_response_field");

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

Code on Jsffidle

Code on Jsffidle

回答by Amila Kandambi

$(".scroller-back").mCustomScrollbar("scrollTo", $("#yourdiv"));