Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript if class is hidden then scroll

scroll to the item only if the class is hidden or when the form opens up. check out the jsfiddle.

http://jsfiddle.net/jdE2v/93/ Can you take a quick look? This was the closest I could get to.

// toggle and hide all but the form u want to edit
$('[class^="toggle-new-form"]').click(function() {
    var el = $(this).parent().next();
    $('[class^="new-form"]').not(el).addClass('hidden');
    el.toggleClass("hidden");
});

// scroll down to view to see all payment Options
$('.scroll-payment-options').click(function() {
    $('body,html').animate({
        scrollTop: $(".scroll-payment-options").offset().top
    }, 800);
});
like image 454
Holly Johnson Avatar asked Aug 31 '26 20:08

Holly Johnson


1 Answers

Use hasClass to check if the element has the hidden class, like so:

// toggle and hide all but the form u want to edit
$('[class^="toggle-new-form"]').click(function() {
  var el = $(this).parent().next();
  $('[class^="new-form"]').not(el).addClass('hidden');
  el.toggleClass("hidden");
});

// scroll down to view to see all payment Options
$('.scroll-payment-options').click(function() {
  if(!($(this).parent().find('[class^="new-form"]').hasClass('hidden'))){
    $('body,html').animate({
      scrollTop: $(".scroll-payment-options").offset().top
    }, 800);
  }
});

Fiddle

like image 117
AM Douglas Avatar answered Sep 02 '26 09:09

AM Douglas