我有以下代码:
<script type="text/javascript">
setInterval(function(){
$("#main").load("select.php?id='.$_GET['id'].' #main")'
}, 3000)
</script>
我想获得div中滚动条的位置,并在刷新时将其加载到该位置。
我的div代码如下。它是回声,因为它在php文件中。
echo "<div class='menu-page-menu-container'; style='height: 420px; overflow: auto'>";
echo "<br>";
echo "<br>";
echo "<table>";
echo "<tr>";
echo "<td><img src='images/time.jpg'> Cet Time</td>";
echo "<td><img src='images/minute.jpg'> Min</td>";
echo "<td>Event</td>";
echo "</tr>";
while ($row = mysql_fetch_assoc($result)) {
$minute=floor($row['timer']/60);
$seconds=$row['timer']-$minute*60;
if ($minute<10)
$m='0'.$minute;
else $m=$minute;
if ($seconds<10)
$s='0'.$seconds;
else $s=$seconds;
$min=$m.':'.$s;
$t=$row['cgtime'];
if(($row['keyword']=='SAFE HOME') || ($row['keyword']=='SAFE AWAY')){
echo "<tr bgcolor='#00FF00'>";
echo "<td><b>".$row['cgtime']."</b></td>";
echo "<td><b>".$min."'</b></td>";
echo "<td><b>".$row['keyword']."</b></td>";
echo "</tr>";
}else if(($row['keyword']=='ATTACK HOME') || ($row['keyword']=='ATTACK AWAY')){
echo "<tr bgcolor='#0000FF'>";
echo "<td><b>".$row['cgtime']."</b></td>";
echo "<td><b>".$min."'</b></td>";
echo "<td><b>".$row['keyword']."</b></td>";
echo "</tr>";
}else if(($row['keyword']=='DANGER HOME') || ($row['keyword']=='DANGER AWAY')|| ($row['keyword']=='DANGER FREE KICK HOME') || ($row['keyword']=='DANGER FREE KICK AWAY') || ($row['keyword']=='DANGER THROW-IN HOME') || ($row['keyword']=='DANGER THROW-IN AWAY')){
echo "<tr bgcolor='#FF0000'>";
echo "<td><b>".$row['cgtime']."</b></td>";
echo "<td><b>".$min."'</b></td>";
echo "<td><b>".$row['keyword']."</b></td>";
echo "</tr>";
}else if(($row['keyword']=='YELLOW CARD HOME')|| ($row['keyword']=='YELLOW CARD AWAY')){
echo "<tr bgcolor='#FFFF00'>";
echo "<td><b>".$row['cgtime']."</b></td>";
echo "<td><b>".$min."'</b></td>";
echo "<td><b>".$row['keyword']."</b></td>";
echo "</tr>";
}else if(($row['keyword']=='RED CARD HOME')|| ($row['keyword']=='RED CARD AWAY')){
echo "<tr bgcolor='#E80000 '>";
echo "<td><b>".$row['cgtime']."</b></td>";
echo "<td><b>".$min."'</b></td>";
echo "<td><b>".$row['keyword']."</b></td>";
echo "</tr>";
}else if(($row['keyword']=='GOAL CONFIRMED')|| ($row['keyword']=='GOAL HOME') || ($row['keyword']=='GOAL AWAY') || ($row['keyword']=='MATCH STARTED') || ($row['keyword']=='MATCH STARTED') || ($row['keyword']=='END MATCH')){
echo "<tr class='invalid'>";
echo "<td><b>".$row['cgtime']."</b></td>";
echo "<td><b>".$min."'</b></td>";
echo "<td><b>".$row['keyword']."</b></td>";
echo "</tr>";
}else{
echo "<tr>";
echo "<td><b>".$row['cgtime']."</b></td>";
echo "<td><b>".$min."'</b></td>";
echo "<td><b>".$row['keyword']."</b></td>";
echo "</tr>";
}
}
echo "</table>";
echo "</div>";
答案 0 :(得分:0)
我无法完全理解你的问题,但也许这会给你一个想法。
$('html,body').animate({scrollTop:$("#masthead").offset().top},'slow');
<script type="text/javascript">
setInterval(function(){
$("#main").load("select.php?id='.$_GET['id'].' #main");
$('html,body').animate({scrollTop:$("#main").offset().top},'slow');
}, 3000)
</script>