2
It is possible to ask through javascript if there is something new in a list ul
- li
?
Like I’m working with a refresh of serInterval
, but it is not very dynamic, pq? When the box receives a new message to Scroll Height
does not descend automatically..
In this example I just received a new message (Red indicates where the scroll is, Blue new space in Scroll Height
). The list ul
- li
But stay where you were last time.
So is there any way you can signal that you’ve received some new li
(message), for the user?
Each li
separating messages are named with a class like this:
<li class="colorBox_<?php print $id_m; ?>">...</li>
// $id_m é o id da mensagem na tabela mysql
CODE setInterval:
var loop = setInterval;
function setLoop(de, para, nome) {
var url_ss = $("#url_b").val();
var url_s = $("#url_s").val();
clearInterval(loop);
loop = setInterval(function() {
$.ajax({
type: "POST",
url: url_ss+"/956309372.php",
data: 'de='+de+'¶='+para+'&url_s='+url_s,
cache: false,
success: function(html) {
$("#mensChat div._5chat").html(html);
}
});
}, 1000);
}
CODE that calls the setInterval:
function openWidChat(de,para,nome) {
var url_s = $("#url_s").val();
$.ajax({
url: url_s +"/chat/chat.php",
data:'de='+de+'¶='+para+'&url_s='+url_s,
type: "POST",
cache: false,
success : function(html){
$("#mensChat div#chat_"+para).html(html);
$("._5chat").scrollTop($("._5chat")[0].scrollHeight);
});
setLoop(de, para, nome);
}
Thanks in advance. ;)
Do you have control over the code that inserts the li? The ideal would be to intercept the moment of insertion, instead of checking with setInterval. If you have no control, is that your plugin/API (chat, apparently) does not offer any callback or event when something new is inserted?
– bfavaretto
If this were done in Angular, it would be superfacil :p
– Wallace Maxters
So, the code that makes the insertion of li, I believe that just insert a class for example, unread, in your setinterval you check if any element has this class, if it has, does the process you need and removes this class.
– Bruno Rigolon