2016-04-27 72 views
0

我自动滚动使用jQuery不工作,这里有什么在我的CSS:自动滚动不工作

#convo_mes{ 
    text-align:left; 
    width:98%; 
    height:80%; 
    background:#fff; 
    border:1px solid #000; 
    overflow-x:auto; 
} 

,并在我的JS:

$(".mes").click(function(){ 
    var user = $(this).attr("id"); 
    $("#convo").html("<b>"+user+"</b>"); 
    $("#convo_ctrl").show(); 
    $(".send_to").attr("id",user); 
    $(".convo_mes").html("Loading conversation <img width='15' height='15' src='./img/load.gif'>"); 
    setTimeout(function(){auto_scrollmes},3000); 
    setTimeout(function(){get_convo(user)},2000); 
}); 

function auto_scrollmes(){ 
    var objDiv = $("#convo_mes"); 
    objDiv.scrollTop = objDiv.scrollHeight; 
} 

它仍然不工作,我不停地变化着的东西但仍然没有运气。 这里是我的HTML代码:

<div id="conversation"> 
<h2>Conversation</h2> 
<hr /> 
<center> 
<div id="convo"> 
Please select a message to load in here! 
</div> 
<div id="convo_mes"> 
<div class="convo_mes"> 

</div> 
</div> 
<div id="convo_ctrl"> 
<textarea spellcheck="false" placeholder="Enter your message here..."          id='mes_text_area'></textarea><a href="#send" id="send_message">Send</a> 
</div> 
</div> 
+1

'的setTimeout(函数(){auto_scrollmes()},3000);'你必须呼叫功能 –

+0

等待让我检查 –

+0

没有工作,即使我添加() –

回答

0

什么是不是在你的代码工作

$(".mes").click(function(){ 
 
    var user = $(this).attr("id"); 
 
    $("#convo").html("<b>"+user+"</b>"); 
 
    $("#convo_ctrl").show(); 
 
    $(".send_to").attr("id",user); 
 
    $(".convo_mes").html("Loading conversation <img width='15' height='15' src='./img/load.gif'>"); 
 
    setTimeout(function(){auto_scrollmes},3000); 
 
    setTimeout(function(){get_convo(user)},2000); 
 
}); 
 

 
function auto_scrollmes(){ 
 
    var objDiv = $("#convo_mes"); 
 
    objDiv.scrollTop = objDiv.scrollHeight; 
 
}
#convo_mes{ 
 
    text-align:left; 
 
    width:98%; 
 
    height:80%; 
 
    background:#fff; 
 
    border:1px solid #000; 
 
    overflow-x:auto; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<div id="conversation"> 
 
<h2>Conversation</h2> 
 
<hr /> 
 
<center> 
 
<div id="convo"> 
 
Please select a message to load in here! 
 
</div> 
 
<div id="convo_mes"> 
 
<div class="convo_mes"> 
 

 
</div> 
 
</div> 
 
<div id="convo_ctrl"> 
 
<textarea spellcheck="false" placeholder="Enter your message here..." id='mes_text_area'></textarea><a href="#send" id="send_message">Send</a> 
 
</div> 
 
</div>

+0

函数auto_scrollmes在3秒后不运行。但我把它放在js上。我将它设置为每1毫秒运行一次,像这样setInterval(auto_scrollmes,100);我在控制台上运行,没有错误仍然不自动滚动。 –