jeudi 10 septembre 2015

Jquery if statement and variable?

I’m stuck on what seems to be the simplest thing. I’m trying to get a basic slider scrolling down a div by 50px each time you press a down button and up when you press an up button. I want the scrolling to end after say 3 clicks. Here’s what I have:

  var countup = -1;
  var countdo = 1;

  if (countdo < 3)
  {
  $('.down-dl').click(function (event) {
    event.preventDefault();

    $('.dl-chapt').css({'transform': 'translateY(-' + (50 * countdo) + 'px) '});

    countdo += 1;
    countup += 1;
  });
  }
  else { //do nothing
  };

And basically the same thing for the up button. It behaves as I’d like except for ending the scroll. The slider doesn’t care about the if statement and just keeps on scrolling. Why isn’t this working? What am I missing?

Aucun commentaire:

Enregistrer un commentaire