Fermare setInterval e riprendere al passaggio del mouse.

The-Night

Utente Attivo
18 Ott 2015
59
0
6
Buona sera, è possibile fermare l'aggiornamento al passaggio del mouse suo div e riprenderlo all'uscita? Se si mi fate un esempio pratico per favore?

PHP:
<script type = "text/javascript">
$(function () {
  var interval = setInterval(function () {
    if ($("#Chat").scrollTop() != $('#Chat')[0].scrollHeight) {
      $("#Chat").scrollTop($("#Chat").scrollTop() + 500);
      } else {
      clearInterval(interval);
    }
  }, 1000);
});
</script>

<div id="Chat" style="float: left; border: 2px #008000 solid; width: 980px; height: 600px; overflow-x:auto; overflow-y:auto; padding: 3px 5px;">
</div>
 

criric

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
21 Ago 2010
5.607
54
48
TN
Ciao, devi separare prima di tutto le due funzioni e usare i metodi mouseover e mouseout per richiamarle , piu o meno cosi
Codice:
$(document).ready(function () {
    $("#Chat").mouseover(function () {
        stop();
    }).mouseout(function () {
        start();
    });
});
var interval;
function start() {
    interval = setInterval(function () {
        if ($("#Chat").scrollTop() != $('#Chat')[0].scrollHeight) {
            $("#Chat").scrollTop($("#Chat").scrollTop() + 500);
        } else {
            stop();
        }
    }, 1000);
}
function stop() {
    if (interval) {
        clearInterval(interval);
    }
}
non ho testato
 

Discussioni simili