0

i have got a question. Is it possible to center an element relative to the screen not to the document. (The document is smaller than the screen) So my actual problem is to detect if the offset is above or under the document. This returns the offset:

var $offset = screen.height - document.height

But I cant detect if it is at the top of the screen or at the bottom :(

Thx

howtoweb
  • 349
  • 1
  • 3
  • 10
  • Possible duplicate of [How to position a div in the middle of the screen when the page is bigger than the screen](http://stackoverflow.com/questions/5012111/how-to-position-a-div-in-the-middle-of-the-screen-when-the-page-is-bigger-than-t) – Tony Dec 28 '16 at 13:01
  • "_relative to the screen_", no, this is not possible. You can position an element relative to it's view window only. Though you can calculate the position of the view window related to the screen, and then reposition the element. I'm not sure, if there's an event for detecting if window is moving. – Teemu Dec 28 '16 at 13:03
  • @Tony no my problem is if the document its smaller than the screen – howtoweb Dec 28 '16 at 13:03
  • Please post a [mcve]. I don't understand what is inside what. –  Dec 28 '16 at 13:10
  • Checkout this link:http://jsfiddle.net/kdzD9/164/. Please let me know if this is not what you want. – Aakash Thakur Dec 28 '16 at 13:10
  • 2
    There's not information enough in your question to answer it properly, but maybe something [like this fiddle](https://jsfiddle.net/959uc9LL/1/)? The fiddle works with FireFox only, but there are `mozInnerScreenY` corresponds in other browsers. If you need the positioning only once, just remove the interval, and run the function only. – Teemu Dec 28 '16 at 14:12

0 Answers0