h5微聊-高仿微信聊天界面实战案例分享

h5仿微信|h5仿微信界面|h5仿微信聊天(单聊、多聊)

h5微聊场景——高仿微信聊天实战项目,可单聊、多聊操作,运用到html5+css3+zepto+weui+wcPop+swiper等多种技术,实现了预览图片(双击放大、手指缩放)、 播放视频及发送消息、表情,打赏、霸屏、发红包等功能,所有弹窗使用wcPop插件统一风格,长按消息可以浮动定位弹出操作菜单。

项目效果图:

h5微聊-高仿微信聊天界面实战案例分享 h5微聊-高仿微信聊天界面实战案例分享

h5微聊-高仿微信聊天界面实战案例分享 h5微聊-高仿微信聊天界面实战案例分享

h5微聊-高仿微信聊天界面实战案例分享 h5微聊-高仿微信聊天界面实战案例分享

h5微聊-高仿微信聊天界面实战案例分享 h5微聊-高仿微信聊天界面实战案例分享


// ...表情、选择区切换
$(".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();
});

// ...处理编辑器信息
var $editor = $(".J__wcEditor"), _editor = $editor[0];
function surrounds(){
	setTimeout(function () { //chrome
		var sel = window.getSelection();
		var anchorNode = sel.anchorNode;
		if (!anchorNode) return;
		if (sel.anchorNode === _editor ||
			(sel.anchorNode.nodeType === 3 && sel.anchorNode.parentNode === _editor)) {
			
			var range = sel.getRangeAt(0);
			var p = document.createElement("p");
			range.surroundContents(p);
			range.selectNodeContents(p);
			range.insertNode(document.createElement("br")); //chrome
			sel.collapse(p, 0);
			
			(function clearBr() {
				var elems = [].slice.call(_editor.children);
				for (var i = 0, len = elems.length; i < len; i++) {
					var el = elems[i];
					if (el.tagName.toLowerCase() == "br") {
						_editor.removeChild(el);
					}
				}
				elems.length = 0;
			})();
		}
	}, 10);
}
// 格式化编辑器包含标签
_editor.addEventListener("click", function () {
	//$(".wc__choose-panel").hide();
}, true);
_editor.addEventListener("focus", function(){
	surrounds();
}, true);
_editor.addEventListener("input", function(){
	surrounds();
}, false);
// 点击表情
$("#J__swiperEmotion").on("click", ".face-list span img", function(){
	var that = $(this), range;

	if(that.hasClass("face")){ //小表情
		var img = that[0].cloneNode(true);
		_editor.focus();
		_editor.blur(); //输入表情时禁止输入法

		setTimeout(function(){
			if(document.selection && document.selection.createRange){
				document.selection.createRange().pasteHTML(img);
			}else if(window.getSelection && window.getSelection().getRangeAt){
				range = window.getSelection().getRangeAt(0);
				range.insertNode(img);
				range.collapse(false);

				var sel = window.getSelection();
				sel.removeAllRanges();
				sel.addRange(range);
			}
		}, 10);
	}else if(that.hasClass("del")){ //删除
		_editor.focus();
		_editor.blur(); //输入表情时禁止输入法

		setTimeout(function(){
			range = window.getSelection().getRangeAt(0);
			range.collapse(false);

			var sel = window.getSelection();
			sel.removeAllRanges();
			sel.addRange(range);
			document.execCommand("delete");
		}, 10);
	} else if(that.hasClass("lg-face")){ //大表情
		var _img = that.parent().html();
		var _tpl = [
			'<li class="me">\
				<div class="content">\
					<p class="author">Nice奶思</p>\
					<div class="msg lgface">'+ _img + '</div>\
				</div>\
				<a class="avatar" href="微聊(好友主页).html"><img src="img/uimg/u__chat-img14.jpg" /></a>\
			</li>'
		].join("");
		$chatMsgList.append(_tpl);

		wchat_ToBottom();
	}
});


h5微聊-高仿微信聊天界面实战案例分享


上一篇:阿里云物联网平台快速入门实践


下一篇:go语言笔记——map map 默认是无序的,不管是按照 key 还是按照 value 默认都不排序