Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> ciągłe pobieranie koordynatów myszki nad tagiem
sokot
post
Post #1





Grupa: Zarejestrowani
Postów: 34
Pomógł: 0
Dołączył: 26.01.2005

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


Witam,

Potrzebuje takiej funkcjonalności jak w temacie. Wiem że jest mouseover ale to działa tylko jak rusza się myszką. Ja oprócz tego potrzebuję że gdy się stanie i jest nad tagiem to dalej wysłane są informację o koordynatach (pomimo że się nie zmieniają).

Jest na to jakaś funkcja ?

Pozdrawiam serdecznie.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 5)
Sephirus
post
Post #2





Grupa: Zarejestrowani
Postów: 1 527
Pomógł: 438
Dołączył: 28.06.2011
Skąd: Warszawa

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


Musisz to oprzeć na intervalu. Zajrzyj tutaj (IMG:style_emoticons/default/wink.gif)
Go to the top of the page
+Quote Post
lukasz1985
post
Post #3





Grupa: Zarejestrowani
Postów: 205
Pomógł: 43
Dołączył: 5.03.2012

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


  1.  
  2. <!--
  3. To change this template, choose Tools | Templates
  4. and open the template in the editor.
  5. -->
  6. <!DOCTYPE html>
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9.  
  10.  
  11. <script type="text/javascript">
  12. var mouseX, mouseY;
  13. window.addEventListener('mousemove', function (event) {
  14.  
  15. mouseX = event.pageX;
  16. mouseY = event.pageY;
  17. console.log(mouseX + ' ' + mouseY);
  18.  
  19. })
  20.  
  21. </script>
  22. </head>
  23. <body>
  24. <div>TODO write content</div>
  25. </body>
  26. </html>
  27.  
Go to the top of the page
+Quote Post
sokot
post
Post #4





Grupa: Zarejestrowani
Postów: 34
Pomógł: 0
Dołączył: 26.01.2005

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


Dzięki za podpowiedzi.

Bardziej przejżyście wygląda ten listener. Ale jak tego użyć ?
Czy to nie jest po prostu nadpisanie funkcji mousemove ?
Bo ja potrzebuje zwracania koordynatów nie tylko jak 'mouse move' (IMG:style_emoticons/default/smile.gif) ale jeszcze jak 'mouse stop' i jest nad divem.

Go to the top of the page
+Quote Post
merk
post
Post #5





Grupa: Zarejestrowani
Postów: 30
Pomógł: 7
Dołączył: 31.05.2006

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


cześć,

tutaj jest dosyć czytelny przykład
http://stackoverflow.com/questions/1608498...l-in-javascript

  1. <body>
  2. <div id="myDiv">test</div>
  3.  
  4. <script type="text/javascript">
  5. document.onmousemove = function(e) {
  6. var event = e || window.event;
  7. window.mouseX = event.clientX;
  8. window.mouseY = event.clientY;
  9. }
  10.  
  11. function mousemov() {
  12. document.getElementById("myDiv").innerHTML = window.mouseX + "--" + window.mouseY;
  13. }
  14.  
  15. window.onload = function() {
  16. setInterval(mousemov, 100);
  17. }
  18. </script>
  19. </body>
  20. </html>
Go to the top of the page
+Quote Post
sokot
post
Post #6





Grupa: Zarejestrowani
Postów: 34
Pomógł: 0
Dołączył: 26.01.2005

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


Dzięki za pomocne uwagi i linki.

Ostatecznie skorzystałem po trochu ze wszystkiego (IMG:style_emoticons/default/smile.gif)

Poniżej zamieszczam kod który mi pomógł i może komuś też pomoże (IMG:style_emoticons/default/wink.gif)

Kod
<script type="text/javascript">
    /* <![CDATA[ */
            $(document).ready(function() {          
                var Xcoord;
                var interval;
                
                $('#center').mousemove(function(e){
                    if (Xcoord == e.pageX) {
                        clearInterval(interval);    
                          interval = setInterval(function(){console.log(Xcoord + "     move your a.... ss :)");}, 50);
                    } else {
                        Xcoord = e.pageX;
                        console.log(e.pageX + "   moving");
                    }
                });
            });
                    
            
        
         /* ]]> */
</script>



Pozdrawiam serdecznie
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 30.09.2025 - 10:04