我需要一些帮助,我目前正在将我网站上的所有内部脚本移植到一个js
文件中,以根据 Google 和 Yahoo 页面速度建议加快我的网站速度。
我的页面 footer.php 中有以下脚本(我正在使用 wordpress)
<script> (function ($) {
jQuery(function () {
var $container = $('#container');
$container.imagesLoaded(function () {
$container.masonry({
itemSelector: '.box',
columnWidth: 100
});
});
$container.infinitescroll({
navSelector: '.post-nav',
nextSelector: '.previous a',
itemSelector: '.box',
loading: {
finishedMsg: 'No more pages to load.',
img: '/wp-content/themes/images/ajax-loader.gif'
}
},
function (newElements) {
var $newElems = $(newElements).css({
opacity: 0
});
$newElems.imagesLoaded(function () {
$newElems.animate({
opacity: 1
});
$container.masonry('appended',
$newElems, true);
});
});
});
})(jQuery)
</script>
如果脚本在我的页脚中,它可以 100% 工作,当我将它添加到单个 js 中时,它会停止工作......
关于为什么会这样的任何想法,以及我应该如何从外部 js 样式表加载脚本,因为它像内联时一样执行。