Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
Keep content position on window resize?

For reprodution set scroll thumb to end of scrollbar and change window size: https://jsfiddle.net/coryphoenixxx/zLq3u4sn/36/

How to stop this and keep sizes of inner box in vw?

<html>
<body>
<div class='box'>
  <div class='inner-box'></div>
  <div class='inner-box'></div>
  <div class='inner-box'></div>
  <div class='inner-box'></div>
  <div class='inner-box'></div>
  <div class='inner-box'></div>
  <div class='inner-box'></div>
  <div class='inner-box'></div>
  <div class='inner-box'></div>
</div>
</body>
</html>
.box {
  width: 30vw;
  height: 12vw;
  border: 0.1vw solid black;
  
  display: flex;
  flex-direction: row;
  overflow-x: scroll;
  overflow-y: hidden;
}

.inner-box {
  margin: 1vw;
  min-width: 7vw;
  height: 7vw;
  border: 0.1vw solid black;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Ok, I found solution

const box = document.querySelector('.box');

let boxScrollPct = 0;
let ignoreScroll = false;
box.addEventListener('scroll', ({ target: t }) => {
  if (ignoreScroll) return;
  boxScrollPct = t.scrollLeft / (t.scrollWidth - t.clientWidth);
});

let timeOutId = null;

window.addEventListener('resize', e => {
  ignoreScroll = true;
  box.scrollLeft = boxScrollPct * (box.scrollWidth - box.clientWidth);
  
  clearTimeout(timeOutId);
  timeOutId = setTimeout(() => {
    ignoreScroll = false;
  }, 50);
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!