h5聊天室模板|仿微信聊天室html5

栏目: Html5 · 发布时间: 5年前

内容简介:原文链接:运用html5开发的仿微信聊天室实战项目weChatRoom,基于h5+css3+zepto+weui+wcPop+swiper等技术混合开发,整体采用flex布局模式,兼容适配各种手机屏幕,实现了消息、表情发送,动图gif,图片、视频预览,红包/打赏等功能。

原文链接: https://www.cnblogs.com/xiaoyan2017/p/9266179.html

运用html5开发的仿微信聊天室实战项目weChatRoom,基于h5+css3+zepto+weui+wcPop+swiper等技术混合开发,整体采用flex布局模式,兼容适配各种手机屏幕,实现了消息、表情发送,动图gif,图片、视频预览,红包/打赏等功能。

h5聊天室模板|仿微信聊天室html5

// ...滚动聊天区底部
function wchat_ToBottom(){
    //$(".wc__chatMsg-panel").animate({scrollTop: $("#J__chatMsgList").height()}, 0);
    $(".wc__slimscroll2").slimscroll({
        scrollBy: $("#J__chatMsgList").height(),
        height: 'auto'
    });
}

// ...表情、选择区切换
$(".wc__editor-panel").on("click", ".btn", function(){
    var that = $(this);
    $(".wc__choose-panel").show();
    if (that.hasClass("btn-emotion")) {
        $(".wc__choose-panel .wrap-emotion").show();
        $(".wc__choose-panel .wrap-choose").hide();
        // 初始化swiper表情
        !emotionSwiper && $("#J__emotionFootTab ul li.cur").trigger("click");
    } else if (that.hasClass("btn-choose")) {
        $(".wc__choose-panel .wrap-emotion").hide();
        $(".wc__choose-panel .wrap-choose").show();
    }
    wchat_ToBottom();
});

// ...处理编辑器信息
// 格式化编辑器包含标签
_editor.addEventListener("click", function () {
    //$(".wc__choose-panel").hide();
}, true);
_editor.addEventListener("focus", function(){
    surrounds();
}, true);
_editor.addEventListener("input", function(){
    surrounds();
}, false);

// 发送信息
var $chatMsgList = $("#J__chatMsgList");
function isEmpty(){
    var html = $editor.html();
    html = html.replace(/<br[\s\/]{0,2}>/ig, "\r\n");
    html = html.replace(/<[^img].*?>/ig, "");
    html = html.replace(/ /ig, "");
    return html.replace(/\r\n|\n|\r/, "").replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, "") == "";
}
$(".J__wchatSubmit").on("click", function(){
    // 判断内容是否为空
    if(isEmpty()) return;

    var html = $editor.html();
    var reg = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|-)+)/g;
    html = html.replace(reg, "<a href='$1$2'>$1$2</a>");
    var msgTpl = [
        '<li class="me">\
            <div class="content">\
                <p class="author">Nice奶思</p>\
                <div class="msg">'+ html +'</div>\
            </div>\
            <a class="avatar" href="微聊(好友主页).html"><img src="img/uimg/u__chat-img14.jpg" /></a>\
        </li>'
    ].join("");
    $chatMsgList.append(msgTpl);

    // 清空聊天框并获取焦点(处理输入法和表情 - 聚焦)
    if(!$(".wc__choose-panel").is(":hidden")){
        $editor.html("");
    }else{
        $editor.html("").focus().trigger("click");
    }
    wchat_ToBottom();
});

h5聊天室模板|仿微信聊天室html5

h5聊天室模板|仿微信聊天室html5

h5聊天室模板|仿微信聊天室html5

h5聊天室模板|仿微信聊天室html5

h5聊天室模板|仿微信聊天室html5

h5聊天室模板|仿微信聊天室html5

h5聊天室模板|仿微信聊天室html5

h5聊天室模板|仿微信聊天室html5

h5聊天室模板|仿微信聊天室html5

h5聊天室模板|仿微信聊天室html5

欢迎大家一起交流、学习 Q:282310962 wx:xy190310


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

程序员的修炼

程序员的修炼

Jeff Atwood / 陆其明、杨溢 / 人民邮电出版社 / 2014-4 / 45.00元

《程序员的修炼——从优秀到卓越》是《高效能程序员的修炼》的姊妹篇,包含了Coding Horror博客中的精华文章。全书分为8章,涵盖了时间管理、编程方法、Web设计、测试、用户需求、互联网、游戏编程以及技术阅读等方面的话题。作者选取的话题,无一不是程序员职业生涯中的痛点。很多文章在博客和网络上的点击率和回帖率居高不下。 Jeff Atwood于2004年创办Coding Horror博客(......一起来看看 《程序员的修炼》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具