Difference between revisions of "Team:CCU Taiwan/Team"

Line 61: Line 61:
 
});
 
});
  
$(window).scroll(function() {
+
// The function actually applying the offset
    var wintop = $(window).scrollTop(), docheight =
+
function offsetAnchor() {
 +
  if (location.hash.length !== 0) {
 +
    window.scrollTo(window.scrollX, window.scrollY - 100);
 +
  }
 +
}
  
    $(document).height(), winheight = $(window).height();
+
// Captures click events of all <a> elements with href starting with #
    var scrolled = (wintop/(docheight-winheight))*100;
+
$(document).on('click', 'a[href^="#"]', function(event) {
 +
  // Click events are captured before hashchanges. Timeout
 +
  // causes offsetAnchor to be called after the page jump.
 +
  window.setTimeout(function() {
 +
    offsetAnchor();
 +
  }, 0);
 +
});
  
    $('.scroll-line').css('height', (scrolled*0.5 + '%'));
+
// Set the offset when entering page with hash present in the url
});
+
window.setTimeout(offsetAnchor, 0);
+
var s = skrollr.init({
+
render: function(data) {
+
  //Log the current scroll position.
+
  $('#info').text(data.curTop);
+
}
+
});;
+
 
 
 
</script>
 
</script>

Revision as of 19:20, 13 October 2018