I would like to run both of these scripts..
var myScroll;
function loaded() {
myScroll = new iScroll('wrapper', { scrollbarClass: 'myScrollbar' });
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', loaded, false);
I want to add this below in addition to what is above.
var myScroll;
function loaded() {
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('DOMContentLoaded', loaded, false);
You can’t create two variables with the same name, or two functions with the same name – not in the same scope, anyway. But you can combine the bodies of your two
loaded()functions into a single function. (Or you can rename themloaded1andloaded2and call them individually, but I wouldn’t do that.)I don’t know what the
myScrollvariable is used for – in the code you’ve shown it is assigned a value but never used. If you don’t ever use it just remove it (and callnew iScroll();directly without assigning the return value to anything. If you do use it you’ll have to rename one or both variables so they don’t clash.So: