Public
Edited
Dec 9, 2022
Insert cell
slider = {
const c = document.createElement("div");
c.className = "container";

const before = c.appendChild(document.createElement("div"));
before.className = "img background-img";

const after = c.appendChild(document.createElement("div"));
after.className = "img foreground-img";

const s = c.appendChild(document.createElement("input"));
s.setAttribute("type","range");
s.setAttribute("min","1");
s.setAttribute("max","100");
s.setAttribute("value","50");
s.setAttribute("name","slider");
s.setAttribute("id","slider");
s.className = "slider";
s.addEventListener('change', slide);
const b = c.appendChild(document.createElement("div"))
b.className = "slider-button"

function slide(e) {
let sliderPos = e.target.value;
// Update the width of the foreground image
after.style.width = sliderPos + '%';
// Update the position of the slider button
b.style.left = 'calc(' + sliderPos + '% - 18px)';
}

return c;
}

Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more