Advertisement
Guest User

Untitled

a guest
May 24th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. var aChildren = $(".cd-faq-categories li a"); // find the a children of the list items
  2.  
  3. var aArray = []; // create the empty aArray
  4. for (var i = 0; i < aChildren.length; i++) {
  5. var aChild = aChildren[i];
  6. var ahref = $(aChild).attr('href');
  7. aArray.push(ahref);
  8. }
  9.  
  10. $(window).scroll(function () {
  11. var windowPos = $(window).scrollTop(); // get the offset of the window from the top of page
  12.  
  13. var windowHeight = $(window).height(); // get the height of the window
  14.  
  15. var docHeight = $(document).height();
  16.  
  17. for (var i = 0; i < aArray.length; i++) {
  18. var theID = aArray[i];
  19. var divPos = $(theID).offset().top;
  20. // get the offset of the div from the top of page
  21. var divHeight = $(theID).height(); // get the height of the div in question
  22.  
  23. if (windowPos >= divPos && windowPos < (divPos + divHeight)) {
  24. $("a[href='" + theID + "']").addClass("selected");
  25. } else {
  26. if ($("a[href='#cld9']"))
  27. {
  28. //...
  29. }
  30. else
  31. {
  32. $("a[href='" + theID + "']").removeClass("selected");
  33. }
  34. }
  35. }
  36. if (windowPos + windowHeight == docHeight) {
  37. alert("gfg");
  38. if (!$(".cd-faq-categories li a").hasClass("selected")) {
  39. var navActiveCurrent = $("li").attr("href");
  40. $("a[href='" + navActiveCurrent + "']").removeClass("selected");
  41. $("li a").addClass("selected");
  42. }
  43. }
  44. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement