jQuery scrollTo プラグインに問題があります。2 つの DIV (nav2
とcontent
) があり、ajax 呼び出しでそれらを埋めています。
var myJs = { ...
getWithAjax : function( targetFile, targetDivId, anchorId ) {
// get is jquery function and wraps ajax call
$.get(targetFile, function(data) {
$('#'+targetDivId).html( data );
if(anchorId !== null){
myJs.doScrollTo(targetDivId, anchorId);
}
});
},
go : function(file1, file2) {
var file1Array, file2Array = new Array();
if(file1 !== null){
file1Array = this.splitLinkFromAnchor(file1);
// update nav2 div
this.getWithAjax(file1Array[0], "nav2", file1Array[1]);
}, //... same with file2 but other div "content"
doScrollTo : function( divId, anchorId ) {
$( '#' + divId ).scrollTo( '#' + anchorId, 0 );
}
// ... further functions
} // end of object literal
ご覧のとおり、コンテンツを取得した後、それを追加してから、anchorId を介してそのターゲット div 内の特定の位置にスクロールしようとします。これはdoScrollTo
、jQuery-Plugin-function をラップする -function を介して行われますscrollTo
。go
ajax 呼び出しのラッパーです。get-Request を作成する前に、指定された入力パラメーターからファイル名と ID (「#」で分割) を抽出します。これがすべて呼び出される方法は次のとおりです。
myJs.go( 'file_a.html#anchor1', 'file_b.html#anchor2' );"
編集: 1 つの DIV、nav2
DIV を使用すると、すべて正常に動作します。しかし、他の DIVcontent
はスクロールされる場合とされない場合があります。また、スクロールされて ai が DIV のスクロールバーを上に移動してからgo
再度呼び出すと、スクロールしなくなります。nav2
そして、私が言ったように、これはすべてDIVでうまく機能します...
誰かが私が間違っていることを理解していますか?
ありがとう。