forked from vyla-entertainment/home-frontend
Released New Website
This commit is contained in:
29
src/scripts/utils/dom.js
Normal file
29
src/scripts/utils/dom.js
Normal file
@@ -0,0 +1,29 @@
|
||||
export function prefersReducedMotion() {
|
||||
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
}
|
||||
|
||||
export function isMobileViewport() {
|
||||
return window.matchMedia('(max-width: 768px)').matches;
|
||||
}
|
||||
|
||||
export function qs(selector, root = document) {
|
||||
return root.querySelector(selector);
|
||||
}
|
||||
|
||||
export function qsa(selector, root = document) {
|
||||
return Array.from(root.querySelectorAll(selector));
|
||||
}
|
||||
|
||||
export function createElement(tag, className) {
|
||||
const el = document.createElement(tag);
|
||||
if (className) el.className = className;
|
||||
return el;
|
||||
}
|
||||
|
||||
export function debounce(fn, delay) {
|
||||
let timeoutId = null;
|
||||
return (...args) => {
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = setTimeout(() => fn(...args), delay);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user