Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding the offset method's return values

I have an element with id="stimulus" in an HTML document.

When I open this document in a browser and use the browser's console to investigate properties of #stimulus, this is what I see:

> $('#stimulus').offset()
< Object {top: 0, left: 0}
> $('#stimulus').css('top')
< "-155.761px"
> $('#stimulus').css('left')
< "253.087px"

How am I to interpret this? How is top within offset different from top accessed using the css method?

like image 848
dbliss Avatar asked Jan 22 '16 23:01

dbliss


People also ask

What is the Offset function?

What is the OFFSET Function? Functions List of the most important Excel functions for financial analysts. This cheat sheet covers 100s of functions that are critical to know as an Excel analyst . OFFSET will return a range of cells. That is, it will return a specified number of rows and columns from an initial range that was specified.

What is the range that offset returns?

The range that the OFFSET function returns can be a single cell or a range of multiple adjacent cells. When returning a range, OFFSET allows you to specify the size by inserting the number of rows and columns.

Can offset return an array of values?

The array of values returned by the OFFSET function is directly entered into the SUM function, which returns a single value. Hence, we do not need it to enter as an array formula.

How to find and change the offset of an element?

An offset is the position of the element from the top and left of the screen. You can find or change these positions by using this method. The syntax of this method is given below:- The description of the parameters are given below. You have to select the element using a selector to return or sets the offset coordinates.


2 Answers

From offset() documentation, offset is from the top of the document; whereas top and left css properties are relative to the parent. Perhaps you wish to look at position() to get the offset relative to the offset parent.

like image 149
Joseph Young Avatar answered Sep 21 '22 08:09

Joseph Young


Offset is the position within the whole page

css top will postion the element relative to it's closest positioned ancestor. That ancestor could be anywhere in the page and so offset and top do not match unless there is no positioned ancestor

like image 42
charlietfl Avatar answered Sep 20 '22 08:09

charlietfl