Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Złe odliczanie
Salur
post 26.06.2015, 19:35:05
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

Posty w temacie
- Salur   [JavaScript]Złe odliczanie   26.06.2015, 19:35:05
- - trueblue   Spróbuj tak: Kodvar mousex = e.pageX - $...   26.06.2015, 19:56:54
- - Salur   Niestety to nic nie pomogło.   26.06.2015, 20:00:25
- - trueblue   http://jsfiddle.net/p7t1k4b7/   26.06.2015, 20:49:12
- - Salur   Co tu duzo mówić, mistrz, dziękuję ! ;D   26.06.2015, 21:09:13


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: 19.07.2025 - 17:14