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

182
Views
Cómo establecer el límite para arrastrar el div vise versa no más del ancho mínimo que es 200

¿Cómo puedo establecer el ancho mínimo para no permitir arrastrar a la izquierda sin ancho en la siguiente muestra?

 const App = () => { const [initialPos, setInitialPos] = React.useState(null); const [initialSize, setInitialSize] = React.useState(null); const initial = (e) => { let resizable = document.getElementById('Resizable'); setInitialPos(e.clientX); setInitialSize(resizable.offsetWidth); } const resize = (e) => { let resizable = document.getElementById('Resizable'); resizable.style.width = `${parseInt(initialSize) + parseInt(e.clientX - initialPos)}px`; } return( <div className = 'Block'> <div id = 'Resizable'/> <div id = 'Draggable' draggable = 'true' onDragStart = {initial} onDrag = {resize} /> </div> ); } ReactDOM.render(<App/>, document.getElementById('root'));

https://codepen.io/erikmartinjordan/pen/dyMEXJb?editors=0110

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

0

Puede ajustar su función de cambio de tamaño para limitar el ancho.

 const resize = (e) => { let resizable = document.getElementById('Resizable'); let newWidth = parseInt(initialSize) + parseInt(e.clientX - initialPos); if (newWidth < 200) { newWidth = 200; } resizable.style.width = `${newWidth}px`; }

Puede configurar 200 para que sea cualquier ancho máximo. ¡Simplemente no olvide cambiar los dos valores de 200, o incluso mejor, haga una variable para ello!

about 4 years ago · Juan Pablo Isaza Report

0

Esto le permitirá mover el extremo hacia la izquierda o hacia la derecha con un máximo de 200 píxeles.

 const initial = (e) => { let resizable = document.getElementById("Resizable"); // lock the start position if (initialPos == null) { setInitialPos(e.clientX); setInitialSize(resizable.offsetWidth); } }; const resize = (e) => { let resizable = document.getElementById("Resizable"); // check for the absolute distance from the start point if (Math.abs(e.clientX - initialPos) < 200) { resizable.style.width = `${ parseInt(initialSize) + parseInt(e.clientX - initialPos) }px`; } };

CódigoPen

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!