MCPcopy Create free account
hub / github.com/hackmdio/codimd / smoothHashScroll

Function smoothHashScroll

public/js/extra.js:1000–1028  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

998
999// smooth all hash trigger scrolling
1000export function smoothHashScroll () {
1001 const hashElements = $("a[href^='#']:not([smoothhashscroll])").toArray()
1002
1003 for (const element of hashElements) {
1004 const $element = $(element)
1005 const hash = element.hash
1006 if (hash) {
1007 $element.on('click', function (e) {
1008 // store hash
1009 const hash = decodeURIComponent(this.hash)
1010 // escape special characters in jquery selector
1011 const $hash = $(hash.replace(/(:|\.|\[|\]|,)/g, '\\$1'))
1012 // return if no element been selected
1013 if ($hash.length <= 0) return
1014 // prevent default anchor click behavior
1015 e.preventDefault()
1016 // animate
1017 $('body, html').stop(true, true).animate({
1018 scrollTop: $hash.offset().top
1019 }, 100, 'linear', () => {
1020 // when done, add hash to url
1021 // (default click behaviour)
1022 window.location.hash = hash
1023 })
1024 })
1025 $element.attr('smoothhashscroll', '')
1026 }
1027 }
1028}
1029
1030function imgPlayiframe (element, src) {
1031 if (!$(element).attr('data-videoid')) return

Callers 2

pretty.jsFile · 0.90
updateViewInnerFunction · 0.90

Calls 2

onMethod · 0.80
stopMethod · 0.45

Tested by

no test coverage detected