“jQuery Obtenez la position de l'élément” Réponses codées

Comment obtenir la position d'élément dans jQuery

.offset() will return the offset position of an element as a simple object, eg:

var position = $(element).offset(); // position = { left: 42, top: 567 }
You can use this return value to position other elements at the same spot:

$(anotherElement).css(position)
Santino

jQuery obtient une position relative de l'élément

//relative Position
let rel = $('.someClass').position();
//absolute Position
let abs = $('.someClass').offset();
Jesus

jQuery se laisse laisser la position

var position = p.position();
var left = position.left; '<-- left value for p
Tense Turtle

jQuery Obtenez la position de l'élément

// Note that:
$(element).offset()
/* tells you the position of an element relative to the document. This works great
in most circumstances, but in the case of position:fixed you can get unexpected
results. If your document is longer than the viewport and you have scrolled
vertically toward the bottom of the document, then your position:fixed element's
offset() value will be greater than the expected value by the amount you have
scrolled. If you are looking for a value relative to the viewport (window), rather
than the document on a position:fixed element, you can subtract the document's
scrollTop() value from the fixed element's offset().top value. */

// Example: 

$("#el").offset().top - $(document).scrollTop()

// If the position:fixed element's offset parent is the document, you want to read:
parseInt($.css('top')) 
// instead.
Ugliest Unicorn

Réponses similaires à “jQuery Obtenez la position de l'élément”

Questions similaires à “jQuery Obtenez la position de l'élément”

Plus de réponses similaires à “jQuery Obtenez la position de l'élément” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code