我有与reCaptcha的联系表单并使用jQuery mCustomScrollbar插件.
问题:当我点击/关注reCaptcha字段时,页面会自动滚动到div的顶部.
见Demo on Jsffidle,Code on Jsfiddle
注意:如果mscrollbar没有在jsfiddle上工作,那就是从malihu网站调用js和css的问题.
- $(".scroller-back").mCustomScrollbar({
- advanced:{
- updateOnContentResize: true
- }
- });
使用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.
- $(".scroller-back").mCustomScrollbar({
- advanced:{
- autoScrollOnFocus: false,updateOnContentResize: true
- }
- });
它适用于所有领域焦点不自动滚动,如何在不使用autoScrollOnFocus的情况下修复此问题:false?
解决方法
解决了
我使用jQuery focus()和mCustomScrollbar scrollTo
- $("#recaptcha_response_field").focus(function() {
- $(".scroller-back").mCustomScrollbar("scrollTo",this);
- });
所以,当焦点(使用点击)recaptcha字段自动滚动到自己.但是当我使用tab键时它不起作用.我试着提醒
- $('#recaptcha_response_field').focus(function() {
- alert('Handler for .focus() called.');
- });
选项卡和单击时它的工作,我不知道jQuery focus()不使用scrollTo self
目前:
我正在使用带有目标ID提交按钮的scrollTo.
- var a=Recaptcha.$("recaptcha_response_field");
- $(a).focus(function() {
- $(".scroller-back").mCustomScrollbar("scrollTo","#submit_button");
- });