|
|
@ -14,23 +14,23 @@ var data = {
|
|
|
|
|
|
|
|
|
|
|
|
function gRotation () {
|
|
|
|
function gRotation () {
|
|
|
|
// console.log("gRotation: %s", data.degRotation);
|
|
|
|
// console.log("gRotation: %s", data.degRotation);
|
|
|
|
return "rotate(" + data.degRotation + "deg)";
|
|
|
|
return 'rotate(' + data.degRotation + 'deg)';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function triangleClick (id) {
|
|
|
|
function triangleClick (id) {
|
|
|
|
console.log("triangleClick: %s", id);
|
|
|
|
console.log('triangleClick: %s', id);
|
|
|
|
render();
|
|
|
|
render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function handleRotate (degs) {
|
|
|
|
function handleRotate (degs) {
|
|
|
|
data.degRotation += degs;
|
|
|
|
data.degRotation += degs;
|
|
|
|
console.log("handleRotate: %s, %s", degs, data.degRotation);
|
|
|
|
console.log('handleRotate: %s, %s', degs, data.degRotation);
|
|
|
|
render();
|
|
|
|
render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function handleReset (degs) {
|
|
|
|
function handleReset (degs) {
|
|
|
|
data.degRotation = degs;
|
|
|
|
data.degRotation = degs;
|
|
|
|
console.log("handleReset: %s", degs);
|
|
|
|
console.log('handleReset: %s', degs);
|
|
|
|
render();
|
|
|
|
render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -39,36 +39,36 @@ function render () {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const hTriangle = (id, degRotation) =>
|
|
|
|
const hTriangle = (id, degRotation) =>
|
|
|
|
h("polygon#" + id, {
|
|
|
|
h('polygon#' + id, {
|
|
|
|
attrs: {
|
|
|
|
attrs: {
|
|
|
|
points: "-50,-88 0,-175 50,-88",
|
|
|
|
points: '-50,-88 0,-175 50,-88',
|
|
|
|
transform: "rotate(" + degRotation + ")",
|
|
|
|
transform: 'rotate(' + degRotation + ')',
|
|
|
|
"stroke-width": 3
|
|
|
|
'stroke-width': 3
|
|
|
|
},
|
|
|
|
},
|
|
|
|
on: { click: [triangleClick, id] }
|
|
|
|
on: { click: [triangleClick, id] }
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const view = (data) =>
|
|
|
|
const view = (data) =>
|
|
|
|
h("div.view", [
|
|
|
|
h('div.view', [
|
|
|
|
h("h1", "Snabbdom SVG Carousel"),
|
|
|
|
h('h1', 'Snabbdom SVG Carousel'),
|
|
|
|
h("svg", { attrs: { width: 380, height: 380, viewBox: [-190, -190, 380, 380] } }, [
|
|
|
|
h('svg', { attrs: { width: 380, height: 380, viewBox: [-190, -190, 380, 380] } }, [
|
|
|
|
h("g#carousel",
|
|
|
|
h('g#carousel',
|
|
|
|
{ style: { "-webkit-transform": gRotation(), transform: gRotation() } }, [
|
|
|
|
{ style: { '-webkit-transform': gRotation(), transform: gRotation() } }, [
|
|
|
|
hTriangle("yellow", 0),
|
|
|
|
hTriangle('yellow', 0),
|
|
|
|
hTriangle("green", 60),
|
|
|
|
hTriangle('green', 60),
|
|
|
|
hTriangle("magenta", 120),
|
|
|
|
hTriangle('magenta', 120),
|
|
|
|
hTriangle("red", 180),
|
|
|
|
hTriangle('red', 180),
|
|
|
|
hTriangle("cyan", 240),
|
|
|
|
hTriangle('cyan', 240),
|
|
|
|
hTriangle("blue", 300)
|
|
|
|
hTriangle('blue', 300)
|
|
|
|
])
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
]),
|
|
|
|
h("button", { on: { click: [handleRotate, 60] } }, "Rotate Clockwise"),
|
|
|
|
h('button', { on: { click: [handleRotate, 60] } }, 'Rotate Clockwise'),
|
|
|
|
h("button", { on: { click: [handleRotate, -60] } }, "Rotate Anticlockwise"),
|
|
|
|
h('button', { on: { click: [handleRotate, -60] } }, 'Rotate Anticlockwise'),
|
|
|
|
h("button", { on: { click: [handleReset, 0] } }, "Reset")
|
|
|
|
h('button', { on: { click: [handleReset, 0] } }, 'Reset')
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener("DOMContentLoaded", () => {
|
|
|
|
window.addEventListener('DOMContentLoaded', () => {
|
|
|
|
var container = document.getElementById("container");
|
|
|
|
var container = document.getElementById('container');
|
|
|
|
vnode = patch(container, view(data));
|
|
|
|
vnode = patch(container, view(data));
|
|
|
|
render();
|
|
|
|
render();
|
|
|
|
});
|
|
|
|
});
|
|
|
|