How to stop scrolling text?

This is my code:

$(document).ready(function() {
    function ticker() {
        $('#ticker li:first').slideUp(function() {
            $(this).appendTo($('#ticker')).slideDown();
        });
    }

    setInterval(function(){ ticker(); }, 3000);
});

I don’t know how to stop scrolling text when I mouse over a specific heading.

Demo

+4
source share
4 answers

Use hover () to clear the interval, and when the mouse leaves, run the ticker again, for example

$(document).ready(function () {
    function ticker() {
        $('#ticker li:first').slideUp(function () {
            $(this).appendTo($('#ticker')).slideDown();
        });
    }

    var clr = null;
    function animate(){
        clr=setInterval(function () {
            ticker();
        }, 3000);
    }
    animate();
    $('#ticker li').hover(function () {
        // clear interval when mouse enters
        clearInterval(clr);
    },function(){
        // again start animation when mouse leaves
        animate();
    });
});

Live demo

+1
source

Minor update in your answer. Use the mouseover and out function.

$(document).ready(function() {
  function ticker() {
     $('#ticker li:first').slideUp(function() {
        $(this).appendTo($('#ticker')).slideDown();
     });
  }

var ticke = setInterval(function(){ ticker(); }, 3000);
    $('#ticker li').mouseover(function() { 
          clearInterval(ticke);
      }).mouseout(function() { 
          ticke= setInterval(function(){ ticker(); }, 3000);
    });
 });

See here Demo

+1
source

try the following:

$(document).ready(function () {
    function ticker() {
        $('#ticker li:first').slideUp(function () {
            $(this).appendTo($('#ticker')).slideDown();
        });
    }

    var clr = null;
    function animate(){
        clr=setInterval(function () {
            ticker();
        }, 3000);
    }
    animate();
    $('#ticker li').hover(function () {
        // clear interval when mouse enters
        clearInterval(clr);
    },function(){
        // again start animation when mouse leaves
        animate();
    });
});
+1
source

The method setIntervalreturns a value idthat can then be passed in clearIntervalto cancel calls to ticker().

0
source

All Articles