Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Maksymalny odstęp między divami
Sexee
post
Post #1





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 31.03.2012

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


Witajcie, czy mógłby ktoś ulepszyć ten kod - tzn ze jak przesuwam diva - to tak by max 10 pikseli można był od drugiego
http://iv.pl/images/53363056074056061328.png to już nie mój poziom, dlatego zwracam się do was.

  1. <script type="text/javascript">
  2.  
  3. var Drag = {
  4.  
  5. obj : null,
  6.  
  7. init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
  8. {
  9. o.onmousedown = Drag.start;
  10.  
  11. o.hmode = bSwapHorzRef ? false : true ;
  12. o.vmode = bSwapVertRef ? false : true ;
  13.  
  14. o.root = oRoot && oRoot != null ? oRoot : o ;
  15.  
  16. if (o.hmode && isNaN(parseInt(o.root.style.left ))) o.root.style.left = "0px";
  17. if (o.vmode && isNaN(parseInt(o.root.style.top ))) o.root.style.top = "0px";
  18. if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right = "0px";
  19. if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
  20.  
  21. o.minX = typeof minX != 'undefined' ? minX : null;
  22. o.minY = typeof minY != 'undefined' ? minY : null;
  23. o.maxX = typeof maxX != 'undefined' ? maxX : null;
  24. o.maxY = typeof maxY != 'undefined' ? maxY : null;
  25.  
  26. o.xMapper = fXMapper ? fXMapper : null;
  27. o.yMapper = fYMapper ? fYMapper : null;
  28.  
  29. o.root.onDragStart = new Function();
  30. o.root.onDragEnd = new Function();
  31. o.root.onDrag = new Function();
  32. },
  33.  
  34. start : function(e)
  35. {
  36. var o = Drag.obj = this;
  37. e = Drag.fixE(e);
  38. var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
  39. var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
  40. o.root.onDragStart(x, y);
  41.  
  42. o.lastMouseX = e.clientX;
  43. o.lastMouseY = e.clientY;
  44.  
  45. if (o.hmode) {
  46. if (o.minX != null) o.minMouseX = e.clientX - x + o.minX;
  47. if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX;
  48. } else {
  49. if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
  50. if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
  51. }
  52.  
  53. if (o.vmode) {
  54. if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;
  55. if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY;
  56. } else {
  57. if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
  58. if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
  59. }
  60.  
  61. document.onmousemove = Drag.drag;
  62. document.onmouseup = Drag.end;
  63.  
  64. return false;
  65. },
  66.  
  67. drag : function(e)
  68. {
  69. e = Drag.fixE(e);
  70. var o = Drag.obj;
  71.  
  72. var ey = e.clientY;
  73. var ex = e.clientX;
  74. var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
  75. var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
  76. var nx, ny;
  77.  
  78. if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
  79. if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
  80. if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
  81. if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
  82.  
  83. nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
  84. ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
  85.  
  86. if (o.xMapper) nx = o.xMapper(y)
  87. else if (o.yMapper) ny = o.yMapper(x)
  88.  
  89. Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
  90. Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
  91. Drag.obj.lastMouseX = ex;
  92. Drag.obj.lastMouseY = ey;
  93.  
  94. Drag.obj.root.onDrag(nx, ny);
  95. return false;
  96. },
  97.  
  98. end : function()
  99. {
  100. document.onmousemove = null;
  101. document.onmouseup = null;
  102. Drag.obj.root.onDragEnd( parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
  103. parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
  104. Drag.obj = null;
  105. },
  106.  
  107. fixE : function(e)
  108. {
  109. if (typeof e == 'undefined') e = window.event;
  110. if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
  111. if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
  112. return e;
  113. }
  114. };
  115.  
  116. </script>
Powód edycji: [phpion]: Zmieniłem temat zgodnie z życzeniem autora.
Go to the top of the page
+Quote Post
!*!
post
Post #2





Grupa: Zarejestrowani
Postów: 4 298
Pomógł: 447
Dołączył: 16.11.2006

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


Wpisz wartość ujemną. Poza tym pokaż działający kod tu http://jsfiddle.net/


--------------------
Nie udzielam pomocy poprzez PW i nie mam GG.
Niektóre języki programowania, na przykład C# są znane z niezwykłej przenośności (kompatybilność ze wszystkimi wersjami Visty jest wiele warta).
Go to the top of the page
+Quote Post
Sexee
post
Post #3





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 31.03.2012

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


Nie potrafię wstawić, dodam że jest to skrypt ze strony: link
w przeglądarce działa, na tym linku co podałeś nie
Go to the top of the page
+Quote Post
!*!
post
Post #4





Grupa: Zarejestrowani
Postów: 4 298
Pomógł: 447
Dołączył: 16.11.2006

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


Twój link nie dziala. Wklejasz tam cały kod w odpowiednie pola, naciskasz save/udate i podajesz nowy link tu.


--------------------
Nie udzielam pomocy poprzez PW i nie mam GG.
Niektóre języki programowania, na przykład C# są znane z niezwykłej przenośności (kompatybilność ze wszystkimi wersjami Visty jest wiele warta).
Go to the top of the page
+Quote Post
Sexee
post
Post #5





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 31.03.2012

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


Jak to wiem, ale przy wklejaniu tego kodu nie ma go.

Ważna jest chyba funkcja, nie styl - nie?
Go to the top of the page
+Quote Post
!*!
post
Post #6





Grupa: Zarejestrowani
Postów: 4 298
Pomógł: 447
Dołączył: 16.11.2006

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


Poszukaj czegoś lepszego, najlepiej w jQuery. lub jQuery UI ma w sobie przesuwanie elementów. I opisz dokładniej o co Ci chodzi, bo tooltip to nie to samo co drag&drop

Ten post edytował !*! 29.06.2012, 16:37:52


--------------------
Nie udzielam pomocy poprzez PW i nie mam GG.
Niektóre języki programowania, na przykład C# są znane z niezwykłej przenośności (kompatybilność ze wszystkimi wersjami Visty jest wiele warta).
Go to the top of the page
+Quote Post
Sexee
post
Post #7





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 31.03.2012

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


Czy jest ktoś w stanie mi pomóc?

P.S. Dziękuję moderatorom za poprawę nazwy.
@up, sory - mój błąd.
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 Aktualny czas: 19.08.2025 - 19:23