在使用 PHP & 实现的聊天室中jQuery ajax 方法,我如何放置表情符号/笑脸?

发布于 2024-12-24 23:12:37 字数 1549 浏览 3 评论 0原文

我创建了 3 个页面 - mainpage.phppost.phpdisplay.php
主页有一个主聊天界面,其 div id 为“chatbox”,以及一个带有提交按钮的文本区域。单击提交按钮后,使用 jQuery 调用 post.php &将用户的消息输入数据库。这没有什么麻烦。

然后我使用 jQuery ajax 方法(见下文)调用 display.php 并将返回的内容放入聊天框 div 中。代码如下:

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');  
                }  
            },  
        });  
    }

注意:这是一个以 2500 毫秒间隔调用的函数 -

setInterval (loadLog, delaytime); 

这也可以正常工作。

现在,在 display.php 中,我曾经

echo PIPHP_ReplaceSmileys($chatdisp['Msg'], 'smileys/');

在聊天中显示表情符号。其代码在这里: http://pluginphp.com/plug-in59.php

我的问题:因为我们正在刷新 < code>display.php 每 2500 毫秒,表情符号每次显示时都会闪烁。文本不会发生这种情况,因为文本速度很快,而图像需要时间加载。这不太理想。有没有办法防止这种闪烁?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半窗疏影 2024-12-31 23:12:37

尝试将微笑设置为背景。 1 个包含所有情感的大文件。它将被加载一次,之后您可以轻松地在块上使用类定义设置 smile。例如:

Try to set smiles as background. 1 large file with all emotions. It will be loaded once, after that You can easily set smile with class definition on block. Ex: <div class="emotion lol"></div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文