微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JQuery mCustomScrollbar autoScrollOnFocus

我有与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);
});

Code on Jsffidle

所以,当焦点(使用点击)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");
});

Code on Jsffidle

原文地址:https://www.jb51.cc/jquery/177168.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐