3

I have created a slideshow plugin that takes a list of images and builds a slide show. The slide show is positioned 100px from the top + $(document).scrollTop().

This is pretty simple and works very well. I am running into some issues when someone one has used css zoom on the page. The calculation for the top position will be off due to the zoom. Does anybody know a good way to correct this/ work around?

Thanks in advance!

5
  • 1
    possible duplicate of Jquery draggable with zoom problem Commented Jan 24, 2013 at 20:15
  • Thanks. That might help. If anyone has input on my particular problem, that would be great. Commented Jan 24, 2013 at 20:17
  • 1
    What exactly do you mean by "css zoom"? Why would your calculation need to take care of that, if it just positions the element 100px from the top? Commented Jan 24, 2013 at 20:29
  • css has a zoom property... I am adding 100px to whatever is returned by $(document).scrollTop(). The issue is that that simple calculation is different depending on the zoom level. Commented Jan 24, 2013 at 20:36
  • 2
    how do you fixed the issue? Commented Apr 15, 2013 at 10:35

2 Answers 2

7

I had the same problem, and found out that jQuery .offset().top is returning some values which depend on window scroll position if there is CSS zoom added to element that is wrapping the elements we need to get position from.

So, I used the native JavaScript .offsetTop in this context:

$("#scrollDestination").get(i).offsetTop;

But, keep in mind that this will get the position relative to it's parent, not like jQuery .scrollTop() which is returning the scroll bar position. So you will need to do some calculations maybe, but at least you will get the consistent returning value for element's position, when you have CSS zoom involved.

Sign up to request clarification or add additional context in comments.

3 Comments

I appreciate this so much. Was so confused why my android gave different values for element.position. Found this : "dimensions may be incorrect when the page is zoomed by the user; browsers do not expose an API to detect this condition." api.jquery.com/position then found your post.
what is the variable i, in .get(i) ?
i is integer for the order number of the element in the DOM
0

this work me

const getScrollTop = function(){
    const zoom = 0.83; // Original zoom: 0.85  - In Js calculate use 0.83 (borders + padding + margin)
    let scroll = window.pageYOffset;
    scroll = (scroll + (scroll * (1 - zoom)));
    return scroll;
}

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.