MCPcopy Create free account
hub / github.com/bevyengine/bevy-website / enable_image_compare

Function enable_image_compare

static/components.js:36–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34// which will set the minimum, maximum, & starting value of the slider. They
35// default to 7%, 93%, and 50% respectively.
36function enable_image_compare() {
37 const image_compares = document.querySelectorAll("div.image-compare");
38 for (const img_cmp of image_compares) {
39 // insert the input only when js is running
40 let style = window.getComputedStyle(img_cmp);
41 const slider = document.createElement('input');
42 slider.type = "range";
43 slider.step = 0.1;
44 slider.min = style.getPropertyValue('--slider-min').replace('%', '');
45 slider.max = style.getPropertyValue('--slider-max').replace('%', '');
46 slider.value = style.getPropertyValue('--slider-value').replace('%', '');
47 slider.ariaLabel = `Slider to compare "${img_cmp.getAttribute('data-title-a')}" and "${img_cmp.getAttribute('data-title-b')}"`
48 img_cmp.appendChild(slider);
49 // setup callback
50 slider.addEventListener("input", (event) => {
51 img_cmp.style.setProperty('--slider-value', clamp(slider.value, slider.min, slider.max) + "%");
52 });
53 }
54}
55
56export { enable_image_compare };

Callers

nothing calls this directly

Calls 1

clampFunction · 0.85

Tested by

no test coverage detected