Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
Cómo obtener el ancho completo de un elemento dentro de un "overflow-x: auto;" ¿área?

Codifiqué esto:

 $(document).ready(function() { $("button").click(function() { alert("Width of #text: " + $("#text").width()); }); });
 * { margin: 0; padding: 0; font-family: sans-serif; } #container { width: 300px; height: 150px; background-color: grey; position: relative; } #scroll-area { overflow-x: auto; height: 100%; } #text { white-space: nowrap; }
 <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <div id="container"> <div id="scroll-area"> <div id="text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</div> </div> </div> <button>Get width of #text</button>

Me gustaría calcular el ancho del elemento #text que está dentro del elemento #container . Actualmente, me muestra 300px como resultado. Pero ese es el ancho del contenedor, y no del elemento de texto.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Pruebe con la función scrollWidth

 $(document).ready(function() { $("button").click(function() { alert("Width of #text: " + $("#scroll-area")[0].scrollWidth); }); });
 * { margin: 0; padding: 0; font-family: sans-serif; } #container { width: 300px; height: 150px; background-color: grey; position: relative; } #scroll-area { overflow-x: auto; height: 100%; } #text { white-space: nowrap; }
 <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <div id="container"> <div id="scroll-area"> <div id="text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</div> </div> </div> <button>Get width of #text</button>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!