我正在尝试用history.js实现历史api,我使用以下教程进入这个主题:
http://webdesign.tutsplus.com/tutorials/lovely-smooth-page-transitions-with-the-history-web-api--cms-26405
我按照描述做了所有的事情,但是当我点击我的网站上的一个链接时,它抛出了跟随错误:
script.js:12未捕获绑定:无法读取未定义的属性“”TypeError“”
你知道我需要怎么修改它才能正常工作吗?我做错什么了?
我正在使用本教程中的jquery、history.js和custom.js文件,如下所示:
var $wrap = $( "#wrap" );
$wrap.on( "click", ".page-link", function( event ) {
event.preventDefault();
if ( window.location === this.href ) {
return;
}
var pageTitle = ( this.title ) ? this.title : this.textContent;
pageTitle = ( this.getAttribute( "rel" ) === "home" ) ? pageTitle : pageTitle + " — Acme";
History.pushState( null, pageTitle, this.href );
} );
History.Adapter.bind( window, "statechange", function() {
var state = History.getState();
$.get( state.url, function( res ) {
$.each( $( res ), function( index, elem ) {
if ( $wrap.selector !== "#" + elem.id ) {
return;
}
$wrap.html( $( elem ).html() );
} );
} );
} );
提前感谢,希望你能帮助我:
发布于 2016-08-11 00:33:17
History.js的文档建议确保将代码加载到IIFE (立即调用的函数表达式)中:
(function(window,undefined){
// Code here
})(window);
来源:https://github.com/browserstate/history.js/ (请参阅“直接安装”部分)
除此之外,请确保您的脚本按照您列出的顺序加载: jQuery、history.js、custom.js。我假设您的代码是用custom.js编写的,并且不在页面上(如果是,那就完全是另外一回事了)。
https://stackoverflow.com/questions/38878203
复制相似问题