Skip to content

Instantly share code, notes, and snippets.

View agusputra's full-sized avatar
🏠
Working from home

Agus Syahputra agusputra

🏠
Working from home
View GitHub Profile
@agusputra
agusputra / do-if-jquery.js
Last active November 3, 2019 10:07
do-if-jquery.js
const detectJQuery = () => typeof jQuery !== 'undefined'
doIf(detectJQuery, main, 1000)
function main() {
jQuery(($) => {
// jQuery detected
})
}
@agusputra
agusputra / sticky.js
Last active November 3, 2019 15:47
Make element sticky to the viewport when scroll
function setSticky(elementId) {
const stickyElement = document.getElementById(elementId)
const stickyTop = stickyElement.offsetTop
const setStickyClass = () => {
if (window.pageYOffset > stickyTop) {
stickyElement.classList.add('sticky')
}
else {
stickyElement.classList.remove('sticky')
(() => {
const execute = () => {
jQuery(($) => {
///
// Do something
///
});
};
const executeIf = (globalProp, execute) => () => {