Skip to content
- Choosing a selection results in a full page refresh.
- Press the space key then arrow keys to make a selection.
- Use left/right arrows to navigate the slideshow or swipe left/right if using a mobile device
/**
* Function to move the background of a website like reptile scales.
*
* @param {string} elementId - The ID of the element to apply the background movement.
* @param {number} speed - The speed of the background movement.
* @param {number} scale - The scale of the background movement.
*/
function moveBackgroundLikeReptileScales(elementId, speed, scale) {
const element = document.getElementById(elementId);
// Check if the element exists
if (!element) {
console.error(`Element with ID "${elementId}" not found.`);
return;
}
// Set the initial background position
let position = 0;
// Function to move the background
function moveBackground() {
// Calculate the new background position
position += speed;
// Apply the background position
element.style.backgroundPosition = `${position}px ${position}px`;
// Apply the background scale
element.style.transform = `scale(${scale})`;
// Request the next animation frame
requestAnimationFrame(moveBackground);
}
// Start the background movement
moveBackground();
}
// Usage Example
// Move the background of the element with ID "background" like reptile scales
moveBackgroundLikeReptileScales("background", 2, 1.2);