Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. //EXECUTES ONLY ONCE
  2. function once(fn, context) {
  3. var result;
  4. return function() {
  5. if(fn) {
  6. result = fn.apply(context || this, arguments);
  7. fn = null;
  8. }
  9. return result;
  10. };
  11. }
  12. // Usage
  13. var split1 = once(function() {
  14. fadeInText(".split1");
  15. });
  16. var pl = once(function() {
  17. fadeInText(".pl");
  18. });
  19. var pl1 = once(function() {
  20. fadeInText(".pl1");
  21. });
  22. var smallp = once(function() {
  23. fadeInText(".smallp");
  24. });
  25. var smallp1 = once(function() {
  26. fadeInText(".smallp1");
  27. });
  28. var smallp2 = once(function() {
  29. fadeInText(".smallp2");
  30. });
  31. var smallp3 = once(function() {
  32. fadeInText(".smallp3");
  33. });
  34. var head0 = once(function() {
  35. fadeInText(".head0");
  36. });
  37.  
  38. $(window).scroll(function() {
  39.  
  40. if( $(this).scrollTop() + $(window).height() > $(".split1").offset().top) {
  41. split1();
  42. }
  43. if( $(this).scrollTop() + $(window).height() > $(".pl").offset().top) {
  44. pl();
  45. }
  46. if( $(this).scrollTop() + $(window).height() > $(".pl1").offset().top) {
  47. pl1();
  48. }
  49. if( $(this).scrollTop() + $(window).height() > $(".smallp").offset().top) {
  50. smallp();
  51. }
  52. if( $(this).scrollTop() + $(window).height() > $(".smallp1").offset().top) {
  53. smallp1();
  54. }
  55. if( $(this).scrollTop() + $(window).height() > $(".smallp2").offset().top) {
  56. smallp2();
  57. }
  58. if( $(this).scrollTop() + $(window).height() > $(".smallp3").offset().top) {
  59. smallp3();
  60. }
  61. if( $(this).scrollTop() + $(window).height() > $(".head0").offset().top) {
  62. head0();
  63. }
  64. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement