gilesadamthomas
gilesadamthomas

Reputation: 181

scroll left distance trigger jquery css

$(document).scroll(function() {

var distanceLeft = $(document).scrollLeft();

if( distanceLeft > 7200)
{
$('#element').animate({height: 421, top: 55}, 1500);
}

Hi I am animating an element when the scroll left reaches more than 7200, how would I reverse this if it was less than 7200 back to original position please any help would be amazing thank you!

Upvotes: 0

Views: 530

Answers (1)

Dirk
Dirk

Reputation: 1020

$(document).scroll(function() {

  var distanceLeft = $(document).scrollLeft();
  var isLeft = false;

  if (distanceLeft > 7200) {
    isLeft = true;
    $('#element').stop(true, false).animate({ height: 421, top: 55 }, 1500);
  } else if (isLeft) {
    isLeft = false;
    $('#element').stop(true, false).animate({ height: origHeight, top: origTop }, 1500);
  }
}

put the original values in the palceholders

Upvotes: 1

Related Questions