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 them loaded1
and loaded2
and call them individually, but I wouldn’t do that.)
I don’t know what the myScroll
variable 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 call new 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:
var myScroll1,
myScroll2;
// combined function
function loaded() {
// statement from the first function
myScroll1 = new iScroll('wrapper', { scrollbarClass: 'myScrollbar' });
// statement from the second function
myScroll2 = 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);
1
solved Need to combine these two javascripts