Как получить значения x и y jquery Draggable

Я создал следующий код:

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#ajax_form').submit(function(){
var dados = jQuery( this ).serialize();jQuery.ajax({
type: "POST",
url: "processa.php",
data: dados,
success: function( data )
{
$('#imagem').attr("src",data);
}
});return false;
});
});
</script>
</head>
<body>// FORM<form method="post" action="" id="ajax_form">
Title <input type = "text" name="titulo" value="">
X <input type = "text" name="x" value="">
Y <input type = "text" name="y" value="">
<input type="submit" name="enviar" value="Enviar" />
</form>// Here I am trying to print the updated image
<img id="imagem" src="<?php $texto?>.jpg">
</body></html>

В файле processa.php

<?phpif ($_SERVER['REQUEST_METHOD'] == 'POST') {

$titulo = $_POST['titulo'];
$x = $_POST['x'];
$y = $_POST['y'];}// Generate image using the GD library
$texto = $titulo; // content from post form
$font_size = 10;
$font_file = 'arial.ttf';
$texto = wordwrap($texto, 11, "\n", true);
$x = $x; // has the form
$y = $y; // has the form
$imagem = imagecreate(50, 50);
$fundo= imagecolorallocate($imagem , 0, 0, 0);
$letra= imagecolorallocate($imagem , 255, 255, 255);imagettftext($imagem, $font_size, 0, $x, $y, $letra, $font_file, $texto);
imagejpeg($imagem, $texto.".jpg", 100); // saved image directory
imagedestroy($imagem);
echo $texto.".jpg";
?>

Работает отлично. Но теперь не знаю, как вставить превратить это в перетаскиваемый.

http://jqueryui.com/draggable/#events

Текст, введенный в «Заголовок», должен иметь возможность перетаскивать и получать значения x и y для позиции для вставки переменных $ x и $ y.

Мне нужен пример того, как получить координаты, чтобы начать

Спасибо, помогите

0

Решение

попробуй этот код

$(function(){$("#demo-box").click(function(e){
var offset = $(this).offset();
var relativeX =(e.pageX - offset.left);
var relativeY =(e.pageY - offset.top);
alert("X: "+ relativeX +"  Y: "+ relativeY);
});
});

я надеюсь, что вы получили ответ

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector