User:Monster Domosed/common.js: Difference between revisionsGive feedback
Undo Tag: Undo |
No edit summary |
||
| Line 30: | Line 30: | ||
startFrame = +el.dataset.startFrame || 0, | startFrame = +el.dataset.startFrame || 0, | ||
sensitivity = +el.dataset.sensitivity || 5; | sensitivity = +el.dataset.sensitivity || 5; | ||
/* ---- 1:1 square for 3D strip ---- */ | |||
var sq = Math.min(fw, fh); | |||
var hint = el.querySelector('.rotatable-model-hint'), | var hint = el.querySelector('.rotatable-model-hint'), | ||
| Line 44: | Line 47: | ||
is2D = false, | is2D = false, | ||
dragOK = true, | dragOK = true, | ||
ready = false; | ready = false; | ||
/* ============================================================ | /* ============================================================ | ||
3D SPRITE STRIP | 3D SPRITE STRIP — each frame is sq × sq | ||
============================================================ */ | ============================================================ */ | ||
var img = makeImg(imageUrl, '', 'rm-strip'); | var img = makeImg(imageUrl, '', 'rm-strip'); | ||
img.style.height = sq + 'px'; | |||
img.style.width = (sq * count) + 'px'; | |||
img.style.height = | |||
img.style.width = ( | |||
img.addEventListener('load', function () { | img.addEventListener('load', function () { | ||
| Line 68: | Line 68: | ||
el.insertBefore(img, el.firstChild); | el.insertBefore(img, el.firstChild); | ||
if (img.complete && img.naturalWidth > 0) { | if (img.complete && img.naturalWidth > 0) { | ||
ready = true; | ready = true; | ||
| Line 76: | Line 75: | ||
/* ============================================================ | /* ============================================================ | ||
2D STATIC IMAGE | 2D STATIC IMAGE — renders at full fw × fh | ||
============================================================ */ | ============================================================ */ | ||
var staticImg = null; | var staticImg = null; | ||
| Line 127: | Line 126: | ||
/* ============================================================ | /* ============================================================ | ||
FRAME DISPLAY | FRAME DISPLAY — sq × sq centred in fw × fh viewport | ||
============================================================ */ | ============================================================ */ | ||
function show(idx) { | function show(idx) { | ||
cur = ((idx % count) + count) % count; | cur = ((idx % count) + count) % count; | ||
img.style.left = ((fw - sq) / 2 - cur * sq) + 'px'; | |||
img.style.top = ((fh - sq) / 2) + 'px'; | |||
img.style.left = | |||
img.style.top = ' | |||
} | } | ||
| Line 187: | Line 184: | ||
/* ============================================================ | /* ============================================================ | ||
DRAG (mouse + touch) | DRAG (mouse + touch) | ||
============================================================ */ | ============================================================ */ | ||
function startDrag(x0) { | function startDrag(x0) { | ||
| Line 200: | Line 195: | ||
acc += dx; | acc += dx; | ||
while (acc >= sensitivity) { | while (acc >= sensitivity) { | ||
acc -= sensitivity; | acc -= sensitivity; | ||
| Line 243: | Line 237: | ||
}, { passive: false }); | }, { passive: false }); | ||
/* ---- wheel | /* ---- wheel ---- */ | ||
el.addEventListener('wheel', function (e) { | el.addEventListener('wheel', function (e) { | ||
if (!dragOK || !ready) return; | if (!dragOK || !ready) return; | ||