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

176
Views
How to make viewport bigger

I'm trying to make a video play automatically (iframe) when it's in the viewport. The problem now is, that the video needs to be big, so in order for it to be in the viewport, it's almost impossible for a user to scroll to the section, so the video is deadcenter...

I'm wondering how I could solve that, if you have any ideas, please let me know.

I'm thinking about the functions which returns if an element is in the viewport which looks like this:

enter image description here

Maybe I can make the viewport bigger?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Well it's me again. I've solved this with a little "hack".

In my html I added an abslute positioned element which is behind the iframe and has no content. Since this is a very small element, it is faster in the viewport and the video starts playing, eventhough the video isn't fully in the viewport.

Not sure if this was the best solution but it worked for me :)

Html

<div class="js-viewport c-video-slider__viewport"></div>

Css

.c-video-slider__viewport {position: absolute; top 45%;}

JS

var vp = document.querySelector(".js-viewport");
if (this.isInViewport(vp) != false) {...}
isInViewport(el) {
    const rect = el.getBoundingClientRect();
    return (
        rect.top >= 0 &&
        rect.left >= 0 &&
        rect.bottom <=
            (window.innerHeight || document.documentElement.clientHeight) &&
        rect.right <=
            (window.innerWidth || document.documentElement.clientWidth)
    );
}
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!