0

I want to determine my ScreenViewport and then position of an element. And want to see if its present in 20% of the bottom of the window, or 20% top of the window.

I have two questions. First when I calculate viewport it returns 339 whereas the element offset returns 763. How is element's offset greater than the viewport?

Second I want to know how can I get the 20% bottom and 20% top of the screen so I can match the offset with them

placement: function (context, source) {
        var windowpos = $(window).height();  //339
        var position = $(source).offset(); //top: 763

        if(position.top < 20% of bottom of windowpos) {
        return "bottom";
        }

        return "auto right";
}
Multi stack
  • 311
  • 3
  • 9
  • 18
  • The `.offset()` method allows us to retrieve the current position of an element relative to the *document* and not window/viewport. Check by viewing `$(document).height()` – Shaunak D Jun 01 '16 at 06:59
  • @ShaunakD but if I want to get the position of my element inside viewport, how would I get it? Any idea? – Multi stack Jun 01 '16 at 07:25
  • Check if this works http://stackoverflow.com/a/31408076/3639582 – Shaunak D Jun 01 '16 at 08:39

0 Answers0