script.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. function divisionnav() {
  2. $('.navigation li:nth-child(n+4)').wrapAll("<div class='cc' />")
  3. }
  4. function activenav() {
  5. // Cache selectors
  6. var lastId,
  7. topMenu = $(".navigation"),
  8. topMenuHeight = topMenu.outerHeight()+500,
  9. // All list items
  10. menuItems = topMenu.find("a"),
  11. // Anchors corresponding to menu items
  12. scrollItems = menuItems.map(function(){
  13. var item = $($(this).attr("href"));
  14. if (item.length) { return item; }
  15. });
  16. // Bind click handler to menu items
  17. // so we can get a fancy scroll animation
  18. // Bind to scroll
  19. $(window).scroll(function(){
  20. // Get container scroll position
  21. var fromTop = $(this).scrollTop()+topMenuHeight;
  22. // Get id of current scroll item
  23. var cur = scrollItems.map(function(){
  24. if ($(this).offset().top < fromTop)
  25. return this;
  26. });
  27. // Get the id of the current element
  28. cur = cur[cur.length-1];
  29. var id = cur && cur.length ? cur[0].id : "";
  30. if (lastId !== id) {
  31. lastId = id;
  32. // Set/remove active class
  33. menuItems
  34. .parent().removeClass("active")
  35. .end().filter("[href='#"+id+"']").parent().addClass("active");
  36. }
  37. });
  38. };
  39. function iswhite() {
  40. $('.navigation li').midnight();
  41. };
  42. $(document).ready(function() {
  43. // divisionnav();
  44. activenav();
  45. iswhite();
  46. });