设想的情况是:
http://website.com/#anchorelement#anchorelement但是,在#anchorelement http://website.com/准备就绪后,将使用jQuery.load() 加载。因此,使用链接http://website.com/#anchorelement不会跳转到#anchorelement,因为在执行跳转时元素尚未加载。
有人对如何使这项工作有任何建议吗?是否可以使用javascript拦截锚跳转,并使其等待jQuery.load()调用完成?
谢谢!
发布于 2015-10-13 20:10:31
$(function(){
// so this is inside your document ready function.
// you need to add a callback
$( somecontainer ).load('somecontent', function(){
// after the content has been loaded
// check if a hash is present in the location
if( window.location.hash != '' ){
// find an element with matching id
var anchor = $( location.hash ).get(0);
// if element was found scroll it into view
if( anchor ){ anchor.scrollIntoView() }
}
});
});https://stackoverflow.com/questions/33111426
复制相似问题