Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
Understand the code snippet in jQuery offset method

I am trying to studying the jQuery method of offset, as below:

    // offset() relates an element's border box to the document origin
    offset: function( options ) {

        // Preserve chaining for setter
        if ( arguments.length ) {
            return options === undefined ?
                this :
                this.each( function( i ) {
                    jQuery.offset.setOffset( this, options, i );
                } );
        }
...

I cannot understand the first paragraph very well. It seems that the method is to check if there are any arguments, and if yes, it will check options, if no options provided, just return the current object, if any options is defined, it will set offset(that is rather strange since this function is to get offset, not to set offset).

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

.offset can be used in two ways: to get the offset, or to set the offset. See the docs.

When called with no arguments, it will:

Description: Get the current coordinates of the first element in the set of matched elements, relative to the document.

Hence the check for arguments.length.

When called with an argument, it will:

.offset( coordinates )

Description: Set the current coordinates of every element in the set of matched elements, relative to the document.

Which is why the code does

if (arguments.length) {
  // set offset of matching elements and return
}
// get and return offset of first matching element
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda