I'm using an example project and, while playing around with it and going into the JavaScript code, I found this function:
(function ()
{
...
...
a lot of code
...
...
...
scrollToPage : function (page, time) {
time = time || 0;
if (page < 0)
page = 0;
else if (page > this.pages.length - 1)
page = this.pages.length - 1;
this.changeTarget(this.pages[page]);
this.scrollTo(-page * this.pageWidth, this.y, time);
}
...
...
})();
I would like to know how this works. To get an idea of why I would want to use this, it's because I want to use the scrollToPage
function outside of this function to navigate on button click. The only experience I have in JavaScript is in Unity3D which is very different than any of web scripting I'm trying out now.
So like this:
(function ()
{
...
...
a lot of code
...
...
...
scrollToPage : function (page, time) {
time = time || 0;
if (page < 0)
page = 0;
else if (page > this.pages.length - 1)
page = this.pages.length - 1;
this.changeTarget(this.pages[page]);
this.scrollTo(-page * this.pageWidth, this.y, time);
}
...
...
})();
function myButtonFunction()
{
scrollToPage(1);
}