Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript] Zatrzymanie animacji po najechaniu myszą
php11
post
Post #1





Grupa: Zarejestrowani
Postów: 215
Pomógł: 5
Dołączył: 11.02.2011

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


Moi drodzy,

jak zatrzymać animację, gdy najadę myszą na element?

  1. var slides = document.querySelectorAll('.mojSlider li');
  2. var currentSlide = 0;
  3. var slideInterval = setInterval(nextSlide,3000);
  4.  
  5. function nextSlide(){
  6. slides[currentSlide].className = 'slajd';
  7. currentSlide = (currentSlide+1)%slides.length;
  8. slides[currentSlide].className = 'slajd aktywny';
  9. }


To powinno zadziałać, ale nie potrafię prawidłowo umieścić w moim kodzie
  1. $(function() {
  2. $('marquee').mouseover(function() {
  3. $(this).attr('scrollamount',0);
  4. }).mouseout(function() {
  5. $(this).attr('scrollamount',5);
  6. });
  7. });
Go to the top of the page
+Quote Post
mortus
post
Post #2





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Trzeba dodać onmouseover i onmouseout eventhandler do każdego slide'u. Pierwszy czyści slideInterval, a drugi ponownie go ustawia. Przykład dla elementów li posiadających klasę slajd:
[JAVASCRIPT] pobierz, plaintext
  1. var interval = setInterval(moveSlide, 3000);
  2. var slides = document.getElementsByClassName("slajd");
  3. for (var i = 0; i < slides.length; i++) {
  4. slides[i].onmouseover = stopSlider;
  5. slides[i].onmouseout = startSlider;
  6. }
  7. function startSlider() {
  8. console.log("Runned");
  9. interval = setInterval(moveSlide, 3000);
  10. }
  11. function stopSlider() {
  12. console.log("Stopped");
  13. clearInterval(interval);
  14. }
  15. function moveSlide() {
  16. console.log("Moved to next slide");
  17. }
[JAVASCRIPT] pobierz, plaintext


Ten post edytował mortus 1.05.2017, 13:39:01
Go to the top of the page
+Quote Post
trueblue
post
Post #3





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

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


Kod
document.querySelector('.mojSlider').addEventListener('mouseenter',function(){
    clearInterval(slideInterval);
});
document.querySelector('.mojSlider').addEventListener('mouseleave',function(){
    slideInterval = setInterval(nextSlide,2000);
});


lub definiujesz zmienną paused (początkowo false). Przy mouseover paused=true, przy mouseleave paused=true. W funkcji nextSlide sprawdzenie czy paused jest true.

Ten post edytował trueblue 1.05.2017, 16:19:12
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: 20.09.2025 - 16:10