I created 3 pages- mainpage.php
, post.php
, display.php
.
mainpage has the main chat interface with a div id 'chatbox', and a textarea with a submit button. On click of the submit button, use jQuery to call post.php
& enter the user's message into the Database. There is no trouble in this.
Then I use the jQuery ajax method (see below) to call display.php
and place the content returned into the chatbox div. Here's the code:
function loadLog(){
if(counter>1)
delaytime=2500;
counter++;
var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
var id=$("#ID").val();
var _url='display.php?Id='+id;
$.ajax({
url:_url,
cache: false,
success: function(html){
$("#chatbox").html(html); //Insert chat from DB into the #chatbox div
var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
if(newscrollHeight > oldscrollHeight){
$("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal');
}
},
});
}
Note: this is a function which is called at interval of 2500 milliseconds-
setInterval (loadLog, delaytime);
This works fine too.
Now, in display.php
, I used
echo PIPHP_ReplaceSmileys($chatdisp['Msg'], 'smileys/');
to display smileys inside the chat. The code for this is here: http://pluginphp.com/plug-in59.php
My problem: Since we are refreshing display.php
every 2500 milliseconds, the emoticons blink every time they are displayed. This doesn't happen with text since text is quick while images take time to load. This is less than ideal. Is there a way to prevent this blinking?