2016-07-31 6 views
2

Scrolling in div Top

<script type="text/javascript"> 
 

 
    $(document).ready(function(){ 
 
     refreshTable(); 
 
    }); 
 

 
    function refreshTable(){ 
 
     $('#mainDiv').load('home.php', function(){ 
 
      setTimeout(refreshTable, 5000); 
 
     }); 
 
    } 
 
</script>

Hallo, ich habe diesen Code/script in 1.php, die alle 5 Sekunden Inhalt von 2.php innen mainDiv lädt. Jetzt möchte ich das mainDiv jedes Mal nach oben scrollen, wenn neue Daten von 2.php in das div geladen werden. Bitte zeigen Sie mir den Code/Skript, wie dies zu erreichen ist. Vielen Dank.

+0

nur verwenden '$ ("# mainDiv") css ("top", 0);.' – Thinker

+0

Welche Zeile in meinem Code oben muss ich einfügen? – kkambi

+0

hinzufügen nach der settimeout-Funktion – Thinker

Antwort

0

Um zu div top zu scrollen, wird der folgende Code verwendet.

$('html, body').animate({ 
    scrollTop: $('#mainDiv').offset().top 
}, 'slow'); 

Bitte überprüfen Sie unten Schnipsel für das ganze Verständnis. Ich habe Dummy-Daten in der Div eingegeben, so dass Sie eine Vorstellung von Scroll-Div bekommen können.

$(document).ready(function(){ 
 
    refreshTable(); 
 
}); 
 

 
function refreshTable(){ 
 
    $('#mainDiv').load('test.php', function(){   
 
     $('html, body').animate({ 
 
      scrollTop: $('#mainDiv').offset().top 
 
     }, 'slow'); 
 
     setTimeout(refreshTable, 5000); 
 
    }); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id="mainDiv"> 
 
    
 
Why do we use it? 
 

 
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). 
 

 
Why do we use it? 
 

 
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). 
 

 
Why do we use it? 
 

 
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). 
 

 
Why do we use it? 
 

 
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). 
 

 
Why do we use it? 
 

 
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). 
 

 
Why do we use it? 
 

 
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). 
 

 
Why do we use it? 
 

 
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). 
 

 
Why do we use it? 
 

 
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). 
 

 
Why do we use it? 
 

 
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). 
 

 
Why do we use it? 
 

 
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). 
 

 
</div>

+0

Danke aber immer noch kein Glück, gibt es sonst noch einen Weg dies zu tun? Sieht so aus, als hätte ich etwas in meinem Code übersehen. Können Sie sich bitte für mich identifizieren? – kkambi

+0

Haben Sie die Demo in Ihrem Code angewendet? Kannst du bitte deine Arbeit teilen? So kann ich identifizieren. –

+0

Ja, ich habe mich beworben, aber nicht gearbeitet. Wie kann ich meinen Code hier für Sie veröffentlichen? – kkambi

2

können Sie einen einfachen Code verwenden, wie unten

gezeigt
$('html,body').animate(
{ scrollTop: $("#div_id").offset().top - 30}, 'slow'); 
+0

Danke aber immer noch kein Glück, gibt es sonst noch einen Weg dies zu tun? – kkambi