<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zoomable Scrollable Div with Buttons</title>
<style>
#zoomableDiv {
width: 300px;
height: 300px;
border: 1px solid #ccc;
overflow: auto;
}
#content {
width: 1000px; /* 大きなコンテンツ */
height: 1000px;
transition: transform 0.3s ease-in-out;
}
.zoomButton {
cursor: pointer;
margin: 5px;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
</head>
<body>
<div id="zoomableDiv">
<div id="content">
<!-- ここに拡大縮小したいコンテンツを配置 -->
<p>This is zoomable and scrollable content.</p>
</div>
</div>
<button class="zoomButton" onclick="zoomIn()">Zoom In</button>
<button class="zoomButton" onclick="zoomOut()">Zoom Out</button>
<script>
var scale = 1;
function zoomIn() {
scale += 0.1;
updateTransform();
}
function zoomOut() {
scale -= 0.1;
updateTransform();
}
function updateTransform() {
// 最小と最大の拡大率を制限(お好みで変更可能)
scale = Math.max(0.5, Math.min(2, scale));
// transformプロパティを使用して拡大縮小
$('#content').css('transform', 'scale(' + scale + ')');
}
</script>
</body>
</html>
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme