Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript]Złe odliczanie
Salur
post
Post #1





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 28.12.2014

Ostrzeżenie: (20%)
X----


Witam, mam problem ponieważ skrypt tooltipa zle odliczna odleglosc od przedmiotu, przy pierwszym obrazku wyświetla się dobrze w drugim już sporo dalej od obrazka a w trzecim to już całkiem gdzie indziej.

  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. $(".tip_trigger").hover(function(){
  4. console.log('hover-on');
  5. tip = $(this).find('.tip');
  6. tip.show();
  7. }, function() {
  8. console.log('hover-off');
  9. tip.hide();
  10. }).mousemove(function(e) {
  11. console.log('mousemove');
  12. var mousex = e.clientX + 20;
  13. var mousey = e.clientY + 20;
  14. var tipWidth = tip.width();
  15. var tipHeight = tip.height();
  16.  
  17. var tipVisX = $(window).width() - (mousex + tipWidth);
  18.  
  19. var tipVisY = $(window).height() - (mousey + tipHeight);
  20.  
  21. if ( tipVisX > 20 ) {
  22. mousex = e.clientX - tipWidth - 70;
  23. } if ( tipVisY > 20 ) {
  24. mousey = e.clientY - tipHeight - 70;
  25. }
  26. tip.css({
  27. top:mousey,
  28. left:mousex
  29. })
  30. });
  31. });
  32. </script>
  33.  
Go to the top of the page
+Quote Post
trueblue
post
Post #2





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Spróbuj tak:
Kod
var mousex = e.pageX - $(document).scrollLeft() + 20;
var mousey = e.pageY - $(document).scrollTop() + 20;



--------------------
Go to the top of the page
+Quote Post
Salur
post
Post #3





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 28.12.2014

Ostrzeżenie: (20%)
X----


Niestety to nic nie pomogło.
Go to the top of the page
+Quote Post
trueblue
post
Post #4





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


http://jsfiddle.net/p7t1k4b7/


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





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 28.12.2014

Ostrzeżenie: (20%)
X----


Co tu duzo mówić, mistrz, dziękuję ! ;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: 22.08.2025 - 08:12