Keep clicking the down button here: http://thomasgrist.tumblr.com/ until you reach the end. The down arrow should disappear one click sooner. Any ideas how I can achieve this with the following code?
I’m a noob but I think that I need to right a condition into my else statement and say if index = something do this but I don’t know what the index should be or how to write this.
$('#next').click(function (event) {
event.preventDefault();
var $current = $('#listOfWork > .current');
if ($current.index() != $('#listOfWork > div').length - 1) {
$("#next").css("display", "inline");
$("#prev").css("display", "inline");
$current.removeClass('current').next().addClass('current');
scrollTo($current.next());
} else {
$("#next").css("display", "none");
}
});
$('#prev').click(function (event) {
event.preventDefault();
var $current = $('#listOfWork > .current');
if (!$current.index() == 0) {
$("#next").css("display", "inline");
$("#prev").css("display", "inline");
$current.removeClass('current').prev().addClass('current');
scrollTo($current.prev());
} else {
$("#prev").css("display", "none");
}
});
I worked out how to do this. Here is the code. If the next div index value equals the amount of divs minus 2 then don’t show the next button. To hide the previous button when there are no more previous divs we write a condition for when current index equals 1.