For this i think the only solution is to make a custom scrollbar (if it is necessary that the image must be above the viewport)
here is the code i have made it according to your code
let stopDrag = false;
const mouse = {}
document.addEventListener('mousemove', (e) => {
mouse.x = e.clientX;
mouse.y = e.clientY;
})
document.getElementsByClassName('scrollbar')[0].addEventListener('mousedown', startDrag)
document.getElementsByClassName('drag')[0].addEventListener('mousedown',startDrag)
document.addEventListener('mouseup', () => {
stopDrag = true;
})
function startDrag() {
stopDrag = false;
let interval = setInterval(() => {
if(mouse.y+180 > 495) {
document.getElementsByClassName('drag')[0].style.top ="495px";
} else
if(mouse.y+180 <217) {
document.getElementsByClassName('drag')[0].style.top ="0px";
}
else
{
document.getElementsByClassName('drag')[0].style.top = mouse.y+(180 + ((Number(document.getElementsByClassName('drag')[0].style.top.split("p")[0]) -760)/3.5));
}
document.getElementsByClassName('window')[0].style.bottom = (Number(document.getElementsByClassName('drag')[0].style.top.split("p")[0]) -760) + "px"
if(stopDrag) {
clearInterval(interval)
}
})
}
.container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 500;
}
.main-content {
display: flex;
width: 100%;
height: 100%;
overflow: auto;
margin: auto;
}
.window {
/*height: 16vw;
width: 27vw;*/
display: flex;
height: 550px;
width: 800px;
position: absolute;
top: 50%;
left: 50%;
border: solid blue 5px;
background-color: black;
margin: auto;
overflow: hidden;
}
.scrollbar {
height: 100%;
width: 2%;
position: fixed;
top: 0%;
right: 10%;
z-index: 3;
background: white;
}
.scrollbar .drag {
background: darkgray;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 10%;
}
.scrollbar .drag:hover {
background: grey;
}
<div class="container">
<div class="main-content">
<div class="window" id="window1" style="transform: translate(-10%, -90%);">
<div class="header" id="window-header">
<img src="https://picsum.photos/800/550">
<div class="scrollbar">
<div class="drag" draggable = false></div>
</div>
<p class="title">navigation</p>
</div>
</div>
</div>
</div>
EXPLANATION
basically i have made a scrollbar with html and css and put it to the very right of the image
hope the html and css is understood
now, for the javascript
first we map the mouse coordinates
const mouse = {}
document.addEventListener('mousemove', (e) => {
mouse.x = e.clientX;
mouse.y = e.clientY;
})
we make the event listeners which call the functions or change the stop drag variable
let stopDrag = false;
document.getElementsByClassName('scrollbar')[0].addEventListener('mousedown', startDrag)
document.getElementsByClassName('drag')[0].addEventListener('mousedown',startDrag)
document.addEventListener('mouseup', () => {
stopDrag = true;
})
then we make the startDrag() function
function startDrag() {
stopDrag = false;
let interval = setInterval(() => {
if(mouse.y+180 > 495) {
document.getElementsByClassName('drag')[0].style.top ="495px";
} else
if(mouse.y+180 <217) {
document.getElementsByClassName('drag')[0].style.top ="0px";
}
else
{
document.getElementsByClassName('drag')[0].style.top = mouse.y+(180 + ((Number(document.getElementsByClassName('drag')[0].style.top.split("p")[0]) -760)/3.5));
}
document.getElementsByClassName('window')[0].style.bottom = (Number(document.getElementsByClassName('drag')[0].style.top.split("p")[0]) -760) + "px"
if(stopDrag) {
clearInterval(interval)
}
})
}
in this first we set the stopdrag to false as the user is currently dragging the scrollbar
then we make an interval to loop the code
mouse.y according coords was mostly trial and error for me
we check if it is above or below the limit if it is we reposition
then we change the top of the scrollbar when dragging (calculations were again trial and error)
then we change the bottom of the window class div to reposition the window class div (because image can't be repositioned by itself; you can make another container on it if you don't want the entire window class div to move) to see it
and if dragging has stopped we clear the interval