我遇到了 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-Requests 之前,它会从给定的输入参数中提取文件名和 id(由“#”分隔)。以下是这一切的名称:
myJs.go( 'file_a.html#anchor1', 'file_b.html#anchor2' );"
编辑:使用一个 DIV,nav2
DIV,一切正常。但是另一个 DIVcontent
有时会滚动,有时则不会。而且,如果它被滚动并且将DIV的滚动条向上移动然后go
再次调用,它就不再滚动了。正如我所说,这一切都适用于nav2
DIV ......
有人知道我在做什么错吗?
谢谢。