Оба метода jQueryUI возвращают объект, который содержит целочисленные координаты свойств верхней и левой позиций. Позиции верхней и левой координат возвращаются в пикселях. Обе функции применяются только к видимым элементам, а не к скрытым элементам.
Пример: в примере приведены верхняя и левая координаты поля, содержащего текст.
|
Выход:
- Перед нажатием любой кнопки:
- После нажатия на кнопку:
смещение:
позиция:
Разница между методами offset () и postion ():
offset() Method | position() Method |
---|---|
The offset() method in jQuery returns the first found position of HTML element with respect to the document. | The position() method in jQuery returns the current position of HTML element with respect to its offset parent. |
The jQuery UI offset() is relative to the document. | The jQuery UI position() is relative to the parent element. |
When you want to position a new element on top of another one which is already existing, its better to use the jQuery offset() method. | When you want to position a new element near another DOM element within the same container, its better to use jQuery position() method. |
The offset() method is mostly used in drag-and-drop functions. | The position() method is used to position an element relative to document, window or other elements like mouse or cursor. |
Рекомендуемые посты:
- JQuery | offset () с примерами
- JQuery | position () с примерами
- Разница между on () и live () или bind () в jQuery
- Как работает AJAX? Разница между угловым JS и JQuery
- CSS | свойство offset-offset
- Как получить смещение часового пояса клиента в JavaScript?
- JQuery | Свойство jQuery.support
- JQuery | jQuery.fx.interval Свойство с примером
- JQuery | Недвижимость jQuery.fx.off
- JQuery | Собственность jquery
- p5.js | Position () Функция
- CSS | Свойство background-position
- CSS | Свойство object-position
- Как разместить div в определенных координатах?
- Как разместить div в нижней части его контейнера с помощью CSS?
0.00 (0%) 0 votes