layui弹窗 预览图片、音频、视频、资源文档在线预览

图片预览

图片预览

function previewImages() {
	let parentObj = $(this).parents('[data-img="prveimgbox"]');//父元素
    layer.photos({
        photos: parentObj,
        closeBtn:1,
        anim: 5
    });
}

视频预览

视频预览
$(document).on('click','[data-role="videoPreview"]',function(){
	var _videouri = $(this).attr('data-uri');
	layer.open({
	  type: 1,
	  title:0,
	  shadeClose:true,
	  area: ['80%', '80%'], //宽高
	  content: '<div style="display:flex;justify-content:center;align-items:center;height:100%"><video src="'+_videouri+'" width="100%"  height="100%" controls></video></div>'
	});
});

音频预览

在这里插入图片描述
在这里插入图片描述

.hwaudio-animate {
	width: 20px;
	height: 20px;
	position: absolute;
	left: 7px;
	background: url('/static/shared/images/hw3.png') no-repeat center;
	background-size: 75%;
}
.hwaudio-animate.active {
	animation: audioanimatesss 1s linear infinite;
}
@keyframes audioanimatesss {
	0% {
		background: url('/static/shared/images/hw1.png') no-repeat center;
		background-size: 75%;
	}
	50% {
		background: url('/static/shared/images/hw2.png') no-repeat center;
		background-size: 75%;
	}
	100% {
		background: url('/static/shared/images/hw3.png') no-repeat center;
		background-size: 75%;
	}
}

$(document).on('click','[data-role="audioPreview"]',function(event){
    $('[data-role="audioPreview"] .hwaudio-animate').removeClass('active');
	if($(this).attr('isError') === '1'){
		layer.msg('播放失败');
	    return;
	}
    if($(this).attr('isPlaying') === '1'){
        $(this).attr('isPlaying','0');
        audioPlayer[0].pause();
        return;
    }
	let audiouri = $(this).attr('data-uri');
    if(!audioPlayer){
        audioPlayer = $('<audio>',{
            src:audiouri,
        });
        audioPlayer.bind('ended',function () {
            console.log('监听结束');
            $('[data-role="audioPreview"] .hwaudio-animate').removeClass('active');
        });
        audioPlayer.bind('error',function () {
			$('[data-role="audioPreview"]').attr('isError','1');
            $('[data-role="audioPreview"] .hwaudio-animate').removeClass('active');
            layer.msg('播放失败');
        });
    }else{
        if(audiouri !== audioPlayer.attr('src')){
            audioPlayer.attr('src',audiouri);
        }
    }
	audioPlayer[0].play();
    $('[data-role="audioPreview"]').attr('isPlaying','0');
    $(this).attr('isPlaying','1');
    $(this).find('.hwaudio-animate').addClass('active');
	event.stopPropagation();
}); 

资源预览

layer.open({
  type: 1,
  title:0,
  shadeClose:true,
  area: ['80%', '80%'], //宽高
  content: '<iframe width="100%" height="100%" src="/js/pdf.js/web/viewer.html?file='+result.data.uri+'"></iframe>',
});
	

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值