question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong vertical center

See original GitHub issue

Hey, I have an issue with the latest version (1.0.9), the images don’t appear in the middle of the screen because the windowCenter function returns a “wrong” value, if I change the code to the one below it does take the correct windowCenter:

function getWindowCenter() {
        var docWidth = docElm.clientWidth || body.clientWidth;
        var docHeight = window.innerHeight; // this didn't work: docElm.clientHeight || body.clientHeight;

        return {
            x: half(docWidth),
            y: half(docHeight)
        };
    }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kingdido999commented, Jan 15, 2017

The current implementation is below:

function getWindowCenter () {
  const windowWidth = Math.min(docElm.clientWidth, window.innerWidth)
  const windowHeight = Math.min(docElm.clientHeight, window.innerHeight)

  return {
    x: half(windowWidth),
    y: half(windowHeight)
  }
}

Notice it’s not perfect though, in modern browsers, it will give you the window center that either excludes scroll bar width and height, which are the desired values, or includes scroll bar width and height (window.innerWidth and window.innerHeight).

References:

0reactions
kobeaertscommented, Jan 15, 2017

It works!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is vertical-align: middle not working on my span or div?
I'm trying to vertically center a span or div element within another div element. However when I put vertical-align: middle , nothing ...
Read more >
Understanding vertical-align, or "How (Not) To ... - Phrogz.net
This question is often followed by I'm using vertical-align:middle but it's not working! The problem here is three-fold: HTML layout traditionally was not ......
Read more >
15 ways to implement vertical alignment with CSS
1. Absolute positioning and margin: auto · 2. The classic top:50% , translateY(-50%) · 3. Centering with tables · 4. The ghost element...
Read more >
How To Center an Element Vertically - W3Schools
Learn how to center an element vertically and horizontally with CSS. I am vertically and horizontally centered. ... <div class="vertical-center">
Read more >
CSS Vertical Align for Everyone (Dummies Included)
I'm having problems centering my content. It's bad, really bad. I couldn't sleep. And you know what? Everyone's struggling with this, it can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found