Skip to content

Instantly share code, notes, and snippets.

View demongodYY's full-sized avatar
:octocat:
Working from Chengdu

demongodYY demongodYY

:octocat:
Working from Chengdu
View GitHub Profile
export const scrollToTop = () => {
const c = document.documentElement.scrollTop || document.body.scrollTop;
if (c > 0) {
window.requestAnimationFrame(scrollToTop);
window.scrollTo(0, c - c / 8);
}
};
export const getScrollPosition = (el = window) =>
@demongodYY
demongodYY / scrollToTop.js
Created June 1, 2021 03:40
schroll to top with animation
const scrollToTop = () => {
const c = document.documentElement.scrollTop || document.body.scrollTop;
if (c > 0) {
window.requestAnimationFrame(scrollToTop);
window.scrollTo(0, c - c / 8);
}
};
@demongodYY
demongodYY / filterDuplicateWhen.js
Created April 22, 2021 09:06
filter duplicate when findIndexFunction
//findCallBack: (item, rawItem) => boolean
const filterDuplicateWhen = (array, findCallback) => {
return array.filter((item, index, rawArray) =>
rawArray.findIndex(rawItem => findCallback(item, rawItem)) === index
);
};
@demongodYY
demongodYY / ranDomKey.js
Created April 21, 2021 03:21
get hex random key
const randomKey = (width = 6) => {
const randomNum = Math.random();
return randomNum.toString(16).slice(-1 * width);
};
@demongodYY
demongodYY / index.html
Created August 9, 2020 14:11
Recreated Valentines Day Card
<div class="bottom">
<div class="paper">
<p>You are<br>the <span class="highlight">CSS</span><br>to my <span class="highlight">HTML</span></p>
</div>
</div>