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

127
Vistas
keep divs in view when browser resized

Im working on a website that behaves like a desktop where users can drag icons round the screen within a container and then click them to open windows. The issue im having is keeping the icons in view at all times so if a user decreases the browser size, the icons dont disappear off to the right. This website achieves it with what seems to be "translate" but im not sure how?

What ive acheived so far is keeping the icons in view by setting their position using %. But as soon as the icon is dragged this position is no long applied and if you resize the browser the icon stays where you left it and will disappear off screen.

See the below example, load the snippet and view it fullscreen, then resize the browser and the text stays in view at all times. But once you move the text then resize the browser it stays where it is rather than moving with the browser.

$(function() {
  $(".drag-me").draggable();
});
.drag-me {
 font-family: 'Lato', sans-serif;
  font-weight: 300;
  font-size: 16px;
  line-height: 16px;
  position: absolute;
    cursor: pointer;
    top: 20% ;
    left: 50% ;
    width:50px;
    }
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>

<div class="drag-me">
  <span>Drag me around!</span>
</div>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use "containment: "window"" option and a helper function.

$(function() {
  $(".drag-me").draggable({
    containment: "window",
    stop: function(e, ui) {
      var perc = ui.position.left / ui.helper.parent().width() * 100;
      ui.helper.css('left', perc + '%');
    }
  });
});
.drag-me {
 font-family: 'Lato', sans-serif;
  font-weight: 300;
  font-size: 16px;
  line-height: 16px;
  position: absolute;
    cursor: pointer;
    top: 20% ;
    left: 50% ;
    width:50px;
    }
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>

<div class="drag-me">
  <span>Drag me around!</span>
</div>

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