Como posso obter uma mudança de posição css para entrar em vigor durante o manipulador de evento de início de um elemento JQuery UI Draggable?
-
12-09-2019 - |
Pergunta
Eu tenho uma situação estranha em que eu preciso modificar a posição de um elemento arrastável assim que o usuário inicia arrastando-o. Assim, durante manipulador de eventos de abertura do elemento arrastável, eu estou tentando definir a posição. Ele não responde à mudança de posição a menos - e isso é estranho - eu fazer algo para causar um erro de javascript depois de eu mudar a posição. Aqui está um exemplo:
<html>
<head>
<title>Drag reposition test</title>
<script type="text/javascript" src="js/css_browser_selector.js"></script>
<script type="text/javascript" src="development-bundle/jquery-1.3.2.js"></script>
<script type="text/javascript" src="development-bundle/ui/jquery-ui-1.7.1.custom.js"></script> <!-- Includes JQuery UI Draggable. -->
<style type="text/css">
#draggable { width: 150px; height: 150px; padding: 0.5em; }
</style>
<script type="text/javascript">
$(function() {
$("#initialdragger").draggable({
start: function(e, ui) {
$('#initialdragger').css('top', 400);
x = y; // Javascript error, which weirdly causes a redraw.
}
});
});
</script>
</head>
<body>
<div id="initialdragger" class="ui-widget-content" style="border-width: 1px; border-color: black; background-color: orange; width: 300px">
<p>Drag me around</p>
</div>
</body>
</html>
Como posso legitimamente causar um redesenho para acontecer neste contexto? pele de JQuery () e show () não funcionam e nem estes métodos .
Solução
Eu acho que a ligação de um evento mousedown vai ter o que você quer
<script type="text/javascript">
$(function() {
$("#initialdragger").draggable();
$('#initialdragger').bind("mousedown", function(e) {
$(this).css('top', 400);
});
});
</script>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow