main.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. var sectionHeight = function() {
  2. var total = $(window).height(),
  3. $section = $('section').css('height','auto');
  4. if ($section.outerHeight(true) < total) {
  5. var margin = $section.outerHeight(true) - $section.height();
  6. $section.height(total - margin - 20);
  7. } else {
  8. $section.css('height','auto');
  9. }
  10. }
  11. $(window).resize(sectionHeight);
  12. $(document).ready(function(){
  13. $("section h1, section h2").each(function(){
  14. $("nav ul").append("<li class='tag-" + this.nodeName.toLowerCase() + "'><a href='#" + $(this).text().toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g,'') + "'>" + $(this).text() + "</a></li>");
  15. $(this).attr("id",$(this).text().toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g,''));
  16. $("nav ul li:first-child a").parent().addClass("active");
  17. });
  18. $("nav ul li").on("click", "a", function(event) {
  19. var position = $($(this).attr("href")).offset().top - 190;
  20. $("html, body").animate({scrollTop: position}, 400);
  21. $("nav ul li a").parent().removeClass("active");
  22. $(this).parent().addClass("active");
  23. event.preventDefault();
  24. });
  25. sectionHeight();
  26. $('img').load(sectionHeight);
  27. });
  28. fixScale = function(doc) {
  29. var addEvent = 'addEventListener',
  30. type = 'gesturestart',
  31. qsa = 'querySelectorAll',
  32. scales = [1, 1],
  33. meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];
  34. function fix() {
  35. meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
  36. doc.removeEventListener(type, fix, true);
  37. }
  38. if ((meta = meta[meta.length - 1]) && addEvent in doc) {
  39. fix();
  40. scales = [.25, 1.6];
  41. doc[addEvent](type, fix, true);
  42. }
  43. };