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

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

内容简介:原文链接:运用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


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

查看所有标签

猜你喜欢:

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

Ordering Disorder

Ordering Disorder

Khoi Vinh / New Riders Press / 2010-12-03 / USD 29.99

The grid has long been an invaluable tool for creating order out of chaos for designers of all kinds—from city planners to architects to typesetters and graphic artists. In recent years, web designers......一起来看看 《Ordering Disorder》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具