Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Wykonanie funkcji po upływie 2 s
pietrov8
post 8.03.2012, 21:50:31
Post #1





Grupa: Zarejestrowani
Postów: 188
Pomógł: 1
Dołączył: 4.07.2009
Skąd: ...

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


Witam.

Poniżej mam napisaną funkcję hover dla pewnego elementu. Chcę by ta funkcja wykonała się tylko wtedy gdy myszka będzie na tym elemencie 2 lub więcej sekund. Gdy zaś będzie krócej lub wcale to ma się nie wykonywać.

Poniżej kod który napisałem:

  1. $(function(){
  2. $('section.zespol_list ul li a').hover(function(){
  3. $(this).next().fadeIn(1000);
  4. },
  5. function(){
  6. $(this).next().fadeOut(1000);
  7. });
  8. });
Go to the top of the page
+Quote Post
lobopol
post 8.03.2012, 22:00:14
Post #2





Grupa: Zarejestrowani
Postów: 1 729
Pomógł: 346
Dołączył: 4.04.2009

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


coś w ten deseń
[JAVASCRIPT] pobierz, plaintext
  1. function addHoverHide(linkClass, layerId) {
  2. var t;
  3. $("." + linkClass).hover(function() {
  4. t = setTimeout(function() {
  5.  
  6. //tuakcja
  7. }, 2000);
  8. }, function() {
  9. clearTimeout(t)
  10. });
  11. }
  12.  
  13. $(document).ready(function () {
  14. addHoverHide("some_link", "this_layer");
  15. });
  16.  
[JAVASCRIPT] pobierz, plaintext


dostosuj pod siebie


--------------------
Go to the top of the page
+Quote Post
Orzeszekk
post 9.03.2012, 00:36:16
Post #3





Grupa: Zarejestrowani
Postów: 260
Pomógł: 14
Dołączył: 8.09.2011

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


Ewentualnie uzyc jQuery + wtyczka jQuery Timers.

W onMouseOver odpalasz wtedy timer na 2000 ms, a w funkcji callback timera robisz co tam chcesz zrobić po uplywie 2 sekund.

jQuery timers ma calkiem spore mozliwosci, i jesli masz czas to polecam sie zainteresowac smile.gif


--------------------
"The first 90 percent of the code accounts for the first 90 percent of the development time. The remaining 10 percent of the code accounts for the other 90 percent of the development time."
Tom Cargill, Bell Labs
Go to the top of the page
+Quote Post
pietrov8
post 9.03.2012, 22:17:59
Post #4





Grupa: Zarejestrowani
Postów: 188
Pomógł: 1
Dołączył: 4.07.2009
Skąd: ...

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


Cytat(Orzeszekk @ 9.03.2012, 00:36:16 ) *
Ewentualnie uzyc jQuery + wtyczka jQuery Timers.

W onMouseOver odpalasz wtedy timer na 2000 ms, a w funkcji callback timera robisz co tam chcesz zrobić po uplywie 2 sekund.

jQuery timers ma calkiem spore mozliwosci, i jesli masz czas to polecam sie zainteresowac smile.gif


Możesz pokazać to na moim przykładzie??

Zrobiłem to tak lecz nie działa:

Kod
var timer;
$(function(){
    $('section.zespol_list ul li a').hover(function(){
        timer = setTimeout(function() {
            $(this).next().fadeIn(1000);
        }, 2000);
    },
    function(){
        clearTimeout(timer);
        $(this).next().fadeOut(1000);
    });
});
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 Wersja Lo-Fi Aktualny czas: 13.07.2025 - 19:44