56 lines
1.6 KiB
HTML
56 lines
1.6 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<style>
|
|
#container {
|
|
width: 300px;
|
|
height: 300px;
|
|
border: 1px solid black;
|
|
overflow: auto;
|
|
}
|
|
#content {
|
|
width: 600px;
|
|
height: 600px;
|
|
background-color: lightgray;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div id="container" onmousedown="startDrag(event)" onmouseup="stopDrag(event)" onmousemove="dragging(event)">
|
|
<div id="content">
|
|
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
|
|
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
|
<!-- Add more content here -->
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
var isDragging = false;
|
|
var container = document.getElementById('container');
|
|
var startX, startY, scrollLeft, scrollTop;
|
|
|
|
function startDrag(e) {
|
|
isDragging = true;
|
|
startX = e.clientX;
|
|
startY = e.clientY;
|
|
scrollLeft = container.scrollLeft;
|
|
scrollTop = container.scrollTop;
|
|
}
|
|
|
|
function stopDrag() {
|
|
isDragging = false;
|
|
}
|
|
|
|
function dragging(e) {
|
|
if (!isDragging) return;
|
|
var x = e.clientX - startX;
|
|
var y = e.clientY - startY;
|
|
container.scrollLeft = scrollLeft - x;
|
|
container.scrollTop = scrollTop - y;
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|