<div class="container">
<div id="zoom-div">
a div
</div>
</div>
.container div {
background: burlywood;
display: inline-block;
width: 100px;
height: 200px;
border: 1px solid aquamarine;
transform-origin: top left;
transition: all 300ms linear;
}
let zoom = 1.0;
let clickCount = 0;
let timer = null;
const dbclick = () => {
if (zoom > 2.5) {
return;
}
zoom = zoom + 0.1;
document.getElementById("zoom-div").style["transform"] = `scale(${zoom})`;
};
const triclick = () => {
if (zoom <= 0.5) {
return;
}
zoom = zoom - 0.1;
document.getElementById("zoom-div").style["transform"] = `scale(${zoom})`;
};
document.getElementById("zoom-div").addEventListener("click", () => {
clickCount = clickCount + 1;
if (timer === null) {
timer = setTimeout(() => {
if (clickCount === 2) {
console.log("双击");
dbclick();
} else if (clickCount >= 3) {
console.log("三连");
triclick();
}
clickCount = 0;
timer = null;
}, 300);
}
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.