0
我的劇本,這一切都正常工作。但我需要加載內嵌/只在特定頁面加載一個js文件。起初我加載我所有的JS腳本在我的頭加載使用getScript加入
這是我需要加載
var myScroll,pullDownEl, pullDownOffset, generatedCount = 0;
function pullDownAction() {
setTimeout(function() {
var el, li, i;
el = document.getElementById('newlist');
if (el.hasChildNodes()) {
while (el.childNodes.length >= 1) {
el.removeChild(el.firstChild);
}
}
for (i=0; i<6; i++) {
li = document.createElement('li');
li.innerText = 'Generated row ' + (++generatedCount);
el.insertBefore(li, el.childNodes[0]);
}
myScroll.refresh();
}, 1000);
}
function loaded() {
pullDownEl = document.getElementById('pullDown');
pullDownOffset = pullDownEl.offsetHeight;
myScroll = new iScroll('wrapper', {
//hideScrollbar: false,
//hScrollbar: false, vScrollbar: false, vScroll: false,
useTransition: true,
topOffset: pullDownOffset,
onRefresh: function() {
if (pullDownEl.className.match('loading')) {
pullDownEl.className = '';
pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Pull down to refresh...';
$('#pullDown').css('display', 'inherit');
$('#pullDown').css('display', 'none');
$('#thelist').css('display', 'none');
$('#newlist').css('display', 'inherit');
}
},
onScrollMove: function() {
if (this.y > 5 && !pullDownEl.className.match('flip')) {
pullDownEl.className = 'flip';
pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Release to refresh...';
$('#pullDown').css('display', 'inherit');
this.minScrollY = 0;
} else if (this.y < 5 && pullDownEl.className.match('flip')) {
pullDownEl.className = '';
pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Pull down to refresh...';
$('#pullDown').css('display', 'inherit');
this.minScrollY = -pullDownOffset;
}
},
onScrollEnd: function() {
if (pullDownEl.className.match('flip')) {
pullDownEl.className = 'loading';
pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Loading...';
pullDownAction();
}
}
});
setTimeout(function() { document.getElementById('wrapper').style.left = '0'; }, 800);
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', function() { setTimeout(loaded, 200); }, false);
在我的頭它與我的其他腳本加載它,但現在我使用jQuery getScript加入JS文件。它加載腳本(使用Firebug),但是當我試着打電話給我的js裏面的功能文件,它給我兩個錯誤
無法讀取空的特性「的offsetHeight」
不能調用方法「刷新「未定義
這是我如何調用使用getScript加入
$(document).ready(function() {
$('.email').click(function(){
$.getScript("assets/js/scroll.js",function() {
pullDownAction();
loaded();
});
});
});
我的js腳本
幫助任何人
只是因爲命名空間污染,我從JavaScript獲得了http://enterprisejquery.com/2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part- 1 / – Michael 2012-03-23 16:31:07