Advertisement
Guest User

Untitled

a guest
May 24th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <div class="wrapper">
  2. <div class="my-class"></div>
  3. <div class="not-my-class"></div>
  4. <div class="my-class"></div>
  5. <div class="not-my-class"></div>
  6. <div class="my-class"></div>
  7. </div>
  8.  
  9. .wrapper {
  10. width: 100%;
  11. height: 100%;
  12. }
  13. .my-class, .not-my-class {
  14. width: 100%;
  15. height: 350px;
  16. margin-top: 10px;
  17. background-color: #888888;
  18. }
  19.  
  20. function fadeIn($element) {
  21. $scrollTop = $(window).scrollTop();
  22. $windowHeight = $(window).height();
  23. $pageHeight = $('body').height();
  24. $elementHeight = $($element).height();
  25. $baseOffset = $($element).offset().top;
  26. $length = 100;
  27. $finalOffset = $baseOffset + ( $elementHeight / 2 );
  28. $current = ( $scrollTop - ( $finalOffset - ($windowHeight / 2 ) - ( $length / 2 ) ) ) / $length;
  29. if ($current > 1) {
  30. $current = 1;
  31. }
  32. else {
  33. if ($current < 0) {
  34. $current = 0;
  35. }
  36. else {}
  37. }
  38. $opacity = $current;
  39. $slide = ( $current * 100 ) - 100;
  40. $(this).css({"opacity": $opacity, "left": $slide, "position": "relative"});
  41. }
  42. $(window).on("load resize scroll",function(){
  43. $('.my-class').each(fadeIn(this));
  44. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement