Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Problem z draggable[JavaScript][PHP], Problem z draggable
nowy16
post 29.08.2011, 16:25:59
Post #1





Grupa: Zarejestrowani
Postów: 71
Pomógł: 0
Dołączył: 29.08.2009

Ostrzeżenie: (0%)
-----


Mam taki problem. Mam skrypt draggable, w którym współrzędne pokazują się w polach input. Jak zrobić aby skrypt odejmował lub dodawał w zależności w którą stronę przesunę obrazek, ale tak, aby odejmował to od wartości podanej w polu Value? Bardzo proszę o gotowe rozwiązanie. Podaję skrypt:
  1.  
  2. <script type="text/javascript">
  3. var ie=document.all;
  4. var nn6=document.getElementById&&!document.all;
  5. var isdrag=false;
  6. var x,y;
  7. var dobj;
  8. function movemouse(e)
  9. {
  10. if (isdrag)
  11. {
  12. var temp_x = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
  13. var temp_y = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
  14. dobj.style.left = temp_x
  15. dobj.style.top = temp_y
  16. document.getElementById('inp_x').value = temp_x
  17. document.getElementById('inp_y').value = temp_y
  18. return false;
  19. }
  20. }
  21. function selectmouse(e)
  22. {
  23. var fobj = nn6 ? e.target : event.srcElement;
  24. var topelement = nn6 ? "HTML" : "BODY";
  25. while (fobj.tagName != topelement && fobj.className != "dragme")
  26. {
  27. fobj = nn6 ? fobj.parentNode : fobj.parentElement;
  28. }
  29. if (fobj.className=="dragme")
  30. {
  31. isdrag = true;
  32. dobj = fobj;
  33. tx = parseInt(dobj.style.left+0,10);
  34. ty = parseInt(dobj.style.top+0,10);
  35. x = nn6 ? e.clientX : event.clientX;
  36. y = nn6 ? e.clientY : event.clientY;
  37. document.onmousemove=movemouse;
  38. return false;
  39. }
  40. }
  41. document.onmousedown=selectmouse;
  42. document.onmouseup=new Function("isdrag=false");
  43.  
  44. <!-- Script by hscripts.com -->
  45.  
  46. <style type="text/css">
  47. .dragme{position:relative;}
  48.  
  49. <table><tr><td align="center">
  50. <img src="./flower.jpg" width="270" height="203" alt="drag-and-drop image script" style="cursor:move;" title="drag-and-drop image script" class="dragme"><a href="http://hscripts.com" style="text-decoration:none;cursor:pointer;font-size:12px;color:green;">H</a>
  51. </td></tr></table>
  52.  
  53. <input type="text" id="inp_x" value="" />
  54. <input type="text" id="inp_y" value="" />
  55.  
<BR>
Pomoże ktoś?

pomoże ktoś? Ponawiam

Ten post edytował nowy16 29.08.2011, 16:20:09
Go to the top of the page
+Quote Post
Rid
post 29.08.2011, 16:37:45
Post #2





Grupa: Zarejestrowani
Postów: 715
Pomógł: 47
Dołączył: 5.12.2010

Ostrzeżenie: (0%)
-----


Można użyć jquery aby łatwo uzyskać ten efekt.
http://api.jquery.com/offset/-jest tam fajny przykład.
Go to the top of the page
+Quote Post
nowy16
post 29.08.2011, 17:02:39
Post #3





Grupa: Zarejestrowani
Postów: 71
Pomógł: 0
Dołączył: 29.08.2009

Ostrzeżenie: (0%)
-----


Być może, ale ten kod co mam jest jak najbardziej odpowiedni, bo przesuwa elementy bez zarzutu, zapisuje dobre współrzędne, ale jeżeli chcę zedytować to zaczyna znowu od (0,0) nawet jak w bazie ma współrzędne (100,2850)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 18.07.2025 - 23:59