Reputation: 121
Helllo,
Trying to create a simple gallery. It looks to see the current gallery - default 0 - and also the total amount of galleries. Each gallery shows two images; it's more like a slideshow, than anything.
When the user clicks the 'next' arrow - it raises the current gallery count. If it exceeds the total number of galleries, it will go back to the first gallery. The same applies for the 'previous' arrow.
It then uses the current gallery integer, to hide and show the necessary slides.
With all of the above mentioned functionality - it will only run once. Either 'previous' or 'next', but never runs more than once.
Jfiddle: http://jsfiddle.net/tKmvn/1/
If all of the additional code is removed, and the following is left, it works more than once.
var curgal = 0;
var maxgal = 2;
function nextgal() {
curgal = curgal + 1;
if (curgal > maxgal) {
curgal = 0;
}
alert(curgal);
}
Upvotes: 0
Views: 69
Reputation: 5064
Your functions are named nextgal
and prevgal
, and inside of them you are using variables with same names:
prevgal = curgal;
curgal = curgal + 1;
nextgal = curgal;
This, basically, replaces your functions with numbers.
In order to solve this problem, you can make those variables local by using the var
keyword.
JSFiddle: http://jsfiddle.net/tKmvn/2/
Upvotes: 1