Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

jQuery .scroll() events

0 votes
16 views
added Apr 3 in jQuery by LC Marshal First Warrant Officer (11,770 points)
edited Jul 12 by LC Marshal
//if scroll more than 147, do this, else do this

window.addEventListener('scroll', function(e) {
  if (window.scrollY > 147) {
    $('body').addClass("fix-prop-header");
  } else {
    $('body').removeClass("fix-prop-header");
  }
});

2 Responses

0 votes
responded Apr 3 by LC Marshal First Warrant Officer (11,770 points)
edited Jul 12 by LC Marshal
//If #target scrolled, find #log and append the div
$( "#target" ).scroll(function() {
  $( "#log" ).append( "<div>Handler for .scroll() called.</div>" );
})

 

0 votes
responded Jun 29 by LC Marshal First Warrant Officer (11,770 points)
edited Jul 12 by LC Marshal
//make sure the event is inserted into the same function
$(window).scroll(function(){
  var $headerSearch = $(".header-search"),
      $showSearch = $('.show-header-search'),
      $hideSearch = $('.hide-header-search');

  if ($(window).scrollTop() >= 300) {
     $('.header-small').fadeIn(200);
     $headerSearch.hide();
  }
  else {
     $('.header-small').hide();
  }

  $showSearch.click(function() {
    $headerSearch.fadeIn(200);
  });

  $hideSearch.click(function() {
    $headerSearch.fadeOut().addClass('hide');
  });

   $showSearch.mouseover(function() {
    $headerSearch.removeClass('hide').addClass('normalize');
  }); 
});
lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...