天天看點

html5直播執行個體|h5仿陌陌、仿火山小視訊

這段時間直播、小視訊比較火,于是空餘時間利用h5開發的仿陌陌、抖音、火山小視訊項目,使用到了html5+css3+jQuery+iscroll+swiper+wlsPop+wcMsgTips等技術架構開發,界面功能效果挺不錯哒!!!

html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊
html5直播執行個體|h5仿陌陌、仿火山小視訊

// 禮物提醒
function giveGifGift(){
	var rndObj = [
		{ giftName: '福到了', giftImg: 'img/gift/gif/gift-gifimg001.gif' },
		{ giftName: '發紅包喽', giftImg: 'img/gift/gif/gift-gifimg002.gif' },
		{ giftName: '大白變超人', giftImg: 'img/gift/gif/gift-gifimg003.gif' },
		{ giftName: '浪漫的熱氣球', giftImg: 'img/gift/gif/gift-gifimg004.gif' },
		{ giftName: '超炫法拉利', giftImg: 'img/gift/gif/gift-gifimg005.gif' },
		{ giftName: '大白鲨', giftImg: 'img/gift/gif/gift-gifimg006.gif' },
		{ giftName: '魔法城堡', giftImg: 'img/gift/gif/gift-gifimg007.gif' }
	];
	var len = rndObj.length, num = Math.floor(Math.random() * len);

	wcTips({
		selector: 'body',
		id: 'wcTips3',
		content: '<div class="wls__gift-fullscreen"><div class="gifGift"><img class="gifimg" src="' + rndObj[num].giftImg + '" /></div></div>',

		shade: true,
		anim: 'zoomInDown',
		time: 10
	});
}


/* 編輯器函數----------------------------------------------------*/
// 滾動到聊天資訊底部
function rollMsg__toBottom(){
	$(".wls__rollMsgPanel").animate({scrollTop: $("#J__chatMsgList").height()}, 300);
}
rollMsg__toBottom();

// >>>表情、選擇區切換
$(".wls__editorPanel").on("click", ".btn", function () {
	var that = $(this);
	$(".wls__choose-panel").show();

	var editorFixBottom = $(".wls__choose-panel").outerHeight();

	if(that.hasClass("btn-face")){
		$(".J__wrapEmotion").show();
		$(".J__wrapChoose").hide();
		// 初始化swiper表情
		!emotionSwiper && $("#J__emotionFootTab ul li.cur").trigger("click");
	}else if(that.hasClass("btn-choose")){
		$(".J__wrapEmotion").hide();
		$(".J__wrapChoose").show();
	}

	// 重置編輯器位置
	$(".wls__editor-panel").css({
		"position": "absolute", "bottom": editorFixBottom
	});
});

// >>>編輯器處理函數
var $chatMsgList = $("#J__chatMsgList");
var $editor = $(".J__wlsEditor"), _editor = $editor[0];

// 定義最後光标位置
var _lastRange = null, _sel = window.getSelection && window.getSelection();
var _rng = {
	getRange: function () {
		if (_sel && _sel.rangeCount > 0) {
			return _sel.getRangeAt(0);
		}
	},
	addRange: function () {
		if (_lastRange) {
			_sel.removeAllRanges();
			_sel.addRange(_lastRange);
		}
	}
}

// 表情處理
$("#J__swiperEmotion").on("click", ".face-list span img", function () {
	var that = $(this), range;

	if (that.hasClass("face")) { //表情
		var img = that[0].cloneNode(true);
		if (!_editor.childNodes.length) {
			_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 = _rng.getRange();
				range.insertNode(img);
				range.collapse(false);

				_lastRange = range; //記錄目前光标位置 (否則光标會跑到表情前面)
				_rng.addRange();
			}
		}, 10);
	} else if (that.hasClass("del")) {
		// _editor.focus();
		_editor.blur(); //輸入表情時禁止輸入法

		setTimeout(function () {
			range = _rng.getRange();
			range.collapse(false);
			document.execCommand("delete");

			_lastRange = range;
			_rng.addRange();
		}, 10);
	}
});
// 發送資訊
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 fastMsgTplIdx = null;
$(".J__fastMsgTpl").on("click", "ul li.more", function () {
	fastMsgTplIdx = wcPop({
		id: 'wcFastMsg',
		skin: 'android',
		title: '給主播請個安吧',
		content: '<div class="wls__fastMsgTpl J__fastMsgTpl"><ul class="clearfix"><li class="item">涼了</li><li class="item">聊天要有禮貌喲!</li><li class="item">守塔</li><li class="item">求簽名</li><li class="item">老司機帶帶我</li><li class="item">确認過眼神,我遇上對的人</li><li class="item">這個人說話很好聽</li><li class="item">慌的一批</li><li class="item">家裡有礦啊</li><li class="item">被安排的明明白白</li></ul></div>',
		xclose: true
	});
});


/* 選擇區函數----------------------------------------------------*/
// 打賞
$(".J__fnDs").on("click", function () {
	var dashangIdx = wcPop({
		skin: 'android',
		title: '<div style="color:#ffe9be;text-align:center;">打賞</div>',
		content: $("#J__popupTmpl-Dashang").html(),
		style: 'background:#e2554b;width:90%;max-width:640px;',
		xclose: true,
		show: function(){
			$("body").on("click", "#J__donateList dd", function () {
				$(this).addClass("cur").siblings().removeClass("cur");
			});
		}
	});
});
// 發紅包
$(".J__fnHb").on("click", function () {
	var hongbaoIdx = wcPop({
		skin: 'android',
		title: '<div style="color:#ffe9be;text-align:center;">發紅包</div>',
		content: $("#J__popupTmpl-Hongbao").html(),
		style: 'background:#e2554b;width:90%;max-width:640px;',
		xclose: true
	});
});
// 發私信
$(".J__fnSx").on("click", function () {
	var sixinIdx = wcPop({
		skin: 'android',
		title: '提示',
		content: '<div style="font-size:16px;">給 <em class="c-23ade5">Salon肥仔</em> 發送私信<div class="flexbox flex-alignc rmt-25"><input class="flex1" type="text" style="border: 0; border-bottom:1px solid #23ade5; padding:.1rem 0;" /></div></div>',
		style: 'width:90%;',
		btns: [
			{
				text: '取消',
				onTap() {
					wcPop.close(sixinIdx);
				}
			},
			{
				text: '發送',
				style: 'color: #23ade5;',
				onTap() {
					...
				}
			}
		]
	});
});


/* 底部toolbar函數----------------------------------------------------*/

// 送一朵花
$(".J__toolbtnSH").on("click", function(){
	var _toolIdx03 = wcPop({
		skin: 'ios',
		title: '<div style="font-size:18px;text-align:left;">提示</div>',
		content: '<div style="text-align:left;padding-bottom:.25rem;">需要支付1微播币,确認支付嗎?<div class="flexbox flex-alignc rmt-25"><input class="cp__checkboxPX-switch" type="checkbox" /><em class="flex1 rml-10 c-b9bbbc">以後不再提醒</em></div></div>',
		style: 'width:90%;',
		btns: [
			{
				text: '取消',
				onTap() {
					wcPop.close(_toolIdx03);
				}
			},
			{
				text: '确定',
				style: 'color: #ff7e00;',
				onTap() {
					...
				}
			}
		]
	});
});

// 送禮物彈窗
$(".J__toolbtnLW").on("click", function(){
	var _toolIdx04 = wcPop({
		skin: 'actionsheet',
		content: $("#J__popupTmpl-giveGift").html(),
		position: 'bottom',
		opacity: 0,
		style: 'background-color:rgba(0,0,0,.9); border-radius: 10px 10px 0 0;'
	});

	// 初始化swiper禮物
	var giftSwiper = new Swiper('.J__swiperGiveGift', {
		pagination: '.pagination-gift',
		paginationClickable: true
	});
});
// 送禮物選項
$("body").on("click", ".J__swiperGiveGift .item", function(){
	var coins = $(this).attr("coins");
	var _tipidx = wcPop({
		id: 'wcCoins',
		skin: 'ios',
		title: '<div style="font-size:18px;text-align:left;">提示</div>',
		content: '<div style="text-align:left;padding-bottom:.25rem;">需要支付'+coins+'微播币,确認支付嗎?<div class="flexbox flex-alignc rmt-25"><input class="cp__checkboxPX-switch" type="checkbox" /><em class="flex1 rml-10 c-b9bbbc">以後不再提醒</em></div></div>',
		style: 'width:90%;',
		btns: [
			{
				text: '取消',
				onTap() {
					wcPop.close(_tipidx);
				}
			},
			{
				text: '确定',
				style: 'color: #ff7e00;',
				onTap() {
					...
				}
			}
		]
	});
});
// 禮物充值彈窗
$("body").on("click", "#J__giftRecharge", function(){
	var _rechargeIdx = wcPop({
		skin: 'actionsheet',
		content: $("#J__popupTmpl-giftRecharge").html(),
		position: 'bottom',
		style: 'border-radius: 10px 10px 0 0;'
	});
});
// 充值選項
$("body").on("click", "#J__rechargeList .item", function(){
	$(this).addClass("on").parent().siblings().find(".item").removeClass("on");
	var num = $(this).find(".money").text();
	$("#J__btnPayment .num").text(num)
});
// 去支付
$("body").on("click", "#J__btnPayment", function(){
	var num = $(this).find(".num").text();
	popupToPay(num);
});
// 支付彈窗
function popupToPay(total){
	var goPayIdx = wcPop({
		id: 'wcGoPay',
		skin: 'ios',
		title: '<div style="font-size:14px;text-align:left;margin:-12px 0 0 -10px;">需支付:' + total + '</div>',
		content: '<div style="font-size:14px;padding:20px 0;">實際支付:<span style="color:#ff7e00;font-size:28px;">' + total + '</span></div><ul class="payType J__payType"><li class="flexbox flex-alignc active"><span class="flex1"><i class="iconfont icon-wxpay"></i> 微信支付</span><i class="iconfont icon-gouxuan"></i></li><li class="flexbox flex-alignc"><span class="flex1"><i class="iconfont icon-alipay"></i> 支付寶支付</span><i class="iconfont icon-gouxuan"></i></li></ul>',
		style: 'width:90%;',
		xclose: true,
		shadeClose: false,
		btns: [
			{
				text: '确認付款',
				style: 'color: #ff7e00;font-size:16px;',
				onTap() {
					...
				}
			}
		]
	});
}
// 支付方式切換(微信、支付寶)
$("body").on("click", ".J__payType li", function(){
	$(this).addClass("active").siblings().removeClass("active");
});

// 設定
$(".J__toolbtnSZ").on("click", function(){
	var _toolIdx05 = wcPop({
		skin: 'actionsheet',
		content: $("#J__popupTmpl-liveShowSetting").html(),
		anim: 'scaleIn',
		xclose: true,
		opacity: 0,
		style: 'background-color:rgba(255,255,255,.9); border-radius: 10px 10px 0 0;'
	});
});           

繼續閱讀