(Created page with "{{CCU_Taiwan/css}} <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://2018.igem.org/Template:CCU_...") |
|||
Line 62: | Line 62: | ||
}); | }); | ||
− | + | // The function actually applying the offset | |
− | + | function offsetAnchor() { | |
− | + | if (location.hash.length !== 0) { | |
− | + | window.scrollTo(window.scrollX, window.scrollY - 90); | |
− | + | } | |
− | }) | + | } |
+ | |||
+ | // Captures click events of all <a> elements with href starting with # | ||
+ | $(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); | ||
+ | }); | ||
+ | |||
+ | // Set the offset when entering page with hash present in the url | ||
+ | window.setTimeout(offsetAnchor, 0); | ||
+ | |||
+ | $(document).scroll(function () { // remove "$" | ||
+ | var y = $(this).scrollTop(); | ||
+ | if (y > 300) { | ||
+ | $('.indicator').fadeIn(); | ||
+ | } | ||
+ | else { | ||
+ | $('.indicator').fadeOut(); | ||
+ | } | ||
+ | }); | ||
</script> | </script> |
Revision as of 21:12, 14 October 2018