2013-06-30 61 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

因爲這是一個非常古老的問題和答案年前接受了這樣更多的背景,我建議你刪除這個答案。 –

相關問題