2013-06-30 56 views
7

我有reCaptcha和使用jQuery mCustomScrollbar插件的联系表单。JQuery mCustomScrollbar autoScrollOnFocus

问题:当我点击/关注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这个问题?

回答

5

解决

使用jQuery focus()和mCustomScrollbar scrollTo

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

Code on Jsffidle

所以,当焦距(使用点击)验证码现场自动滚动到自我。但是当我使用Tab键时它不起作用。我试图与警报

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

这是工作的时候选项卡并单击,我不知道的jQuery focus()scrollTo

工作对于本:

我使用scrollTo与目标ID的提交按钮。

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

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

Code on Jsffidle

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

因为这是一个非常古老的问题和答案年前接受了这样更多的背景,我建议你删除这个答案。 –

相关问题