![]() |
![]() |
![]()
Post
#1
|
|
![]() Developer Grupa: Moderatorzy Postów: 3 045 Pomógł: 290 Dołączył: 20.01.2007 ![]() |
Witam,
piszę w JavaScript obsługę "pływających" okien. Kiedyś coś takiego napisałem i działało dość dobrze (z tym że dużo kodu było przeplatane z HTML'em), postanowiłem całkowicie oddzielić kod HTML od JavaScript i napotkałem na mały problem. Podczas przesuwania okna powoli wszystko jest w porządku, ale przy gwałtowniejszym ruchu okno się gubi (głównie ruch pionowy, przy poziomym trudno uzyskać taki efekt). Poniżej przedstawiam kod oraz link do przykładu. Kod var PositionX = 0; var PositionY = 0; var WindowHandle = false; window.onload = function () { var Window = document.getElementById ('windowTest'); var Elements = Window.getElementsByTagName ('div'); for (var Increment = 0; Increment < Elements.length; Increment++) { if (Elements[Increment].getAttribute ('class') == 'title') { Elements[Increment].onmouseover = function (Event) { } Elements[Increment].onmousedown = function (Event) { this.style.cursor = 'move'; if (WindowHandle == false) { PositionX = Event.layerX; PositionY = Event.layerY; WindowHandle = true; } return true; } Elements[Increment].onmousemove = function (Event) { if (WindowHandle == true) { Window.setAttribute ('class', 'window move'); Window.style.top = (Event.pageY - PositionY) + 'px'; Window.style.left = (Event.pageX - PositionX) + 'px'; } document.getElementById ('X').innerHTML = Window.style.top; document.getElementById ('Y').innerHTML = Event.pageY; document.getElementById ('Z').innerHTML = PositionY; } Elements[Increment].onmouseup = function (Event) { Window.setAttribute ('class', 'window'); this.style.cursor = 'default'; WindowHandle = false; } Elements[Increment].onmouseout = function (Event) { Window.setAttribute ('class', 'window'); this.style.cursor = 'default'; WindowHandle = false; } } } } Przykład (testowałem to tylko pod Firefox'em 3.x, zapewne pod innymi przeglądarkami działać nie będzie). |
|
|
![]() |
![]()
Post
#2
|
|
![]() Grupa: Zarejestrowani Postów: 2 148 Pomógł: 230 Dołączył: 26.03.2008 Ostrzeżenie: (0%) ![]() ![]() |
mozna pozyczyc kawalek twojego kodu
![]() -------------------- ET LINGUA EIUS LOQUETUR IUDICIUM
|
|
|
![]()
Post
#3
|
|
![]() Developer Grupa: Moderatorzy Postów: 3 045 Pomógł: 290 Dołączył: 20.01.2007 ![]() |
Zależy jaki kawałek i do czego
![]() EDIT: Problem dość banalny ![]() Kod Elements[Increment].onmousemove = function (Event) na: Kod document.onmousemove = function (Event) Co siłą rzeczy jest oczywiste. |
|
|
![]()
Post
#4
|
|
![]() Grupa: Zarejestrowani Postów: 84 Pomógł: 6 Dołączył: 26.03.2008 Skąd: Łódź Ostrzeżenie: (0%) ![]() ![]() |
http://mintajax.pl/ - Ta lekka bibloteka AJAX udostępnia coś takiego, można podejrzeć jak tam to jest zrobione.
![]() -------------------- NULL;
|
|
|
![]() ![]() |
![]() |
Wersja Lo-Fi | Aktualny czas: 19.07.2025 - 12:41 |