27Jan/120
DOMContentLoaded could not load a function()
I ran into a problem where my DOMContentLoaded could not load a function(); on a specific version of Appcelerator (Titanium). Like:
<script type="text/javascript">
var scroll1, scroll2, myScroll;
function loaded() {
//iScroll - Scroll up and down
scroll1 = new iScroll('RightContent', { useTransition:true });
scroll2 = new iScroll('MainContent2', { useTransition:true });
//iScroll - Snap left and right
myScroll = new iScroll('wrapper', {
snap: true,
momentum: false,
hScrollbar: false,
onScrollEnd: function () {
document.querySelector('#indicator > li.active').className = '';
document.querySelector('#indicator > li:nth-child(' + (this.currPageX+1) + ')').className = 'active';
}
});
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', loaded, false);
</script>
But if I changed it so DOMContentLoaded loaded the code directly it worked again.
<script type="text/javascript">
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
window.addEventListener('DOMContentLoaded', function () {
var scroll1, scroll2, myScroll;
//iScroll - Scroll up and down
scroll1 = new iScroll('RightContent', { useTransition:true });
scroll2 = new iScroll('MainContent2', { useTransition:true });
//iScroll - Snap left and right
myScroll = new iScroll('wrapper', {
snap: true,
momentum: false,
hScrollbar: false,
onScrollEnd: function () {
document.querySelector('#indicator > li.active').className = '';
document.querySelector('#indicator > li:nth-child(' + (this.currPageX+1) + ')').className = 'active';
}
});
});
</script>
Hope this will help other in the same situation.