Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda