2017-06-20 3 views
0

Guten Morgen, ich bitte um Hilfe für meinen Code. Es funktioniert, aber ich möchte den Inhalt sofort und nicht nach Hover-In und Hover-Out laden.clearInterval auf schweben nach der fertigen Seite

Wie kann ich es beheben? danke

`

<script> 
function aggiornatabella(){ 
$('#tabella').load('pres_tl_admin_ajax_load.php'); // carica il contenuto dal file e lo mette nel div #tabella 
} 

$(document).hover(
function(){ // quando è tutto pronto... 
clearInterval(timer); 
      }, 
function(){ 
timer = setInterval(aggiornatabella, 1000); // ogni secondo aggiorna la tabella 
      } 
       ); 

</script> 
<? print"<div id=\"tabella\"></div>"; ?> 

[gelöst] Dies ist die Lösung, ich danke Ihnen allen

`

<script> 
function aggiornatabella(){ 
$('#tabella').load('pres_tl_admin_ajax_load.php'); // carica il contenuto dal file e lo mette nel div #tabella 
} 

$(document).ready(function(){ 
    var interval = setInterval(aggiornatabella , 2000); 
$('#tabella').hover(function (ev) { 
    clearInterval(interval); 
}, function (ev) { 
    interval = setInterval(aggiornatabella , 2000); 
}); 
}); 
</script> 
<? print"<div id=\"tabella\"></div>"; ?> 

`

`

+1

direkt die Methode aufrufen, dh '$ (function() {aggiornatabella();});' – Satpal

Antwort

0

Try this:

$(document).ready(function() { 
    $(document).hover(
    function(){ // quando è tutto pronto... 
     clearInterval(timer); 
    }, 
    function(){ 
     timer = setInterval(aggiornatabella, 1000); // ogni secondo aggiorna la tabella 
    } 
); 
}); 
+0

Sorry, ich habe mich geirrt, ich möchte clearInterval auf Hover-in und setinterval auf Hover-out Aber die Seite lädt nur nach Hover-In und Hover-Out Während ich sofort – Pino

+0

laden möchte, wird das Skript wahrscheinlich ausgeführt, bevor das Dokument fertig ist. –

+0

Danke, schon gelöst – Pino

0

Der meiste JavaScript-Code ist nur Unsinn. Du brauchst nur eine Zeile davon. Ich habe auch einen Wrapper, so dass diese geladen werden, wenn das Dokument fertig ist, statt sofort, wo es nicht funktionieren könnte:

$(function() { 
    $('#tabella').load('pres_tl_admin_ajax_load.php'); 
} 

Sie können den Rest des JavaScript entfernen.

+0

Sorry, ich war falsch, Ich möchte clearInterval auf schweben-in und setInterval on hover-out Aber die Seite lädt nur nach Hover-in und Hover-out Während ich sofort laden möchte – Pino