1

I need to get div top position relevant to window.

I used jquery functions such as:

scrollTop()
offset()
position()
offset().top

My Problem when I open the page on widescreen resolution such as 1360x768 values are differ from normal aspect ratio such as 1024x768

I want to trigger what ever event when scrolling to certain position... how can I do this without confusion between wide screen/normal screen aspect ratios because when I used mentioned functions... returned values were differ

  • Can you clarify what you mean by "div top position"? Do you mean top most DOM element relative to the window? The question you stated is not clear. – peterdotjs Mar 03 '15 at 08:52
  • Yes, you can use position function and then get top value of div "position.top". – Yogesh Sharma Mar 03 '15 at 08:52
  • `$('div').offset().top` would give you the offset top position relative to the parent body. – Jai Mar 03 '15 at 08:54
  • Thanx all I edited my question with more details – Almoujtahed Mar 03 '15 at 09:10
  • Duplicate of http://stackoverflow.com/questions/17441065/how-to-detect-scroll-position-of-page-using-jquery – peterdotjs Mar 03 '15 at 09:16
  • Not a duplicate,,, I asking about specific situation, getting different scroll position values when we open page in widescreen vs normal aspect ratios – Almoujtahed Mar 03 '15 at 09:23
  • How is there a difference between widescreen versus narrow screen? Either a) you depend on a fixed position relative to the top of the window or b) you look for the current height of some DOM element. I don't see how the window size/aspect ratio affects the method of triggering an event based on the scroll location. – peterdotjs Mar 03 '15 at 09:43
  • I don't want to use fixed tags positions, returned values are differ between wire/narrow screens – Almoujtahed Mar 03 '15 at 10:26

1 Answers1

0

I thins you should use

position: fixed;

css style. Because fixed can make the element relative to window. That really means a window, not document.