I am making a photo slider. If you click the previous or next button, the margin-left keeps adding or subtracting a variable, which is set to 5px. However, I want to limit the distance the slider goes left or right, so that it doesn’t slide so far that there is white space.
To limit the boundary, there is a conditional statement that assigns the variable a value of 5px if the margin-left is between 10px and -100px. Otherwise, the variable is set to 0px.
And this does work. If you go too far to the left or right, the slider just stops. But once the boundary is met, the previous and next buttons do not work. Any tips?
You can view my code here:
jsfiddle.net/xpfbh/2/
I have updated your fiddle. I had to change your if condition to include the margin range as well as the direction. Also removed the test variable and moved the statement which sets the margin within the if block. I didn’t think the else block was needed, so I removed it as well.