MUI 图片预览并在底部添加文字说明

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_25027593/article/details/80000388

效果图如下:


实现方法如下:

1.引入相关css

.mui-preview-image.mui-fullscreen {
    position: fixed;
    z-index: 20;
    background-color: #000;
}
			
.mui-preview-header,
.mui-preview-footer {
    position: absolute;
    width: 100%;
    left: 0;
    z-index: 10;
}
			
.mui-preview-header {
    height: 44px;
    top: 0;
}
			
.mui-preview-footer {
    height: 50px;
    bottom: 0px;
}
			
.mui-preview-header .mui-preview-indicator {
    display: block;
    line-height: 25px;
    color: #fff;
    text-align: center;
    margin: 15px auto 4;
    width: 70px;
    background-color: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    font-size: 16px;
}
			
.mui-preview-image {
    display: none;
    -webkit-animation-duration: 0.5s;
    animation-duration: 0.5s;
    -webkit-animation-fill-mode: both;
    animation-fill-mode: both;
}
			
.mui-preview-image.mui-preview-in {
    -webkit-animation-name: fadeIn;
    animation-name: fadeIn;
}
			
.mui-preview-image.mui-preview-out {
    background: none;
    -webkit-animation-name: fadeOut;
    animation-name: fadeOut;
}
			
.mui-preview-image.mui-preview-out .mui-preview-header,
.mui-preview-image.mui-preview-out .mui-preview-footer {
    display: none;
}
			
.mui-zoom-scroller {
    position: absolute;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    align-items: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    justify-content: center;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    -webkit-backface-visibility: hidden;
}
			
.mui-zoom {
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
}
			
.mui-slider .mui-slider-group .mui-slider-item img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
}
			
.mui-android-4-1 .mui-slider .mui-slider-group .mui-slider-item img {
    width: 100%;
}
			
.mui-android-4-1 .mui-slider.mui-preview-image .mui-slider-group .mui-slider-item {
    display: inline-table;
}
			
.mui-android-4-1 .mui-slider.mui-preview-image .mui-zoom-scroller img {
    display: table-cell;
    vertical-align: middle;
}
			
.mui-preview-loading {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    display: none;
}
			
.mui-preview-loading.mui-active {
    display: block;
}
			
.mui-preview-loading .mui-spinner-white {
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -25px;
    margin-top: -25px;
    height: 50px;
    width: 50px;
}
			
.mui-preview-image img.mui-transitioning {
    -webkit-transition: -webkit-transform 0.5s ease, opacity 0.5s ease;
    transition: transform 0.5s ease, opacity 0.5s ease;
}
			
@-webkit-keyframes fadeIn {
    0% {
	opacity: 0;
    }
    100% {
	opacity: 1;
    }
}
			
@keyframes fadeIn {
    0% {
	opacity: 0;
    }
    100% {
	opacity: 1;
    }
}
			
@-webkit-keyframes fadeOut {
    0% {
	opacity: 1;
    }
    100% {
	opacity: 0;
    }
}
			
@keyframes fadeOut {
    0% {
	opacity: 1;
    }
    100% {
	opacity: 0;
    }
}
			
p img {
    max-width: 100%;
    height: auto;
}
			
.mui-slider-img-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    color: #fff;
    line-height: 22px;
    padding: 10px;
    background-color: rgba(0, 0, 0, .6);
}

2.引入mui.min.js

  引入mui.previewimage.js并修改mui.previewimage.js里面“proto.refresh ”函数

  引入mui.zoom.js

  以上js都在hello mui工程里面可以找到。

itemStr = itemTemplate.replace('{{src}}', itemData.src).replace('{{lazyload}}', itemData.lazyload).replace('{{style}}', style);
//在mui.previewimage.js上面一句话下面添加以下代码
if(itemData.el.getAttribute('data-content') && itemData.el.getAttribute('data-content') != '') {
    if(itemData.el.getAttribute('data-desc') && itemData.el.getAttribute('data-desc') != '')
        itemStr = itemStr.replace('{{content}}', '<div class="mui-slider-img-content">' + itemData.el.getAttribute("data-content") + "</br>" + "<div style='color:#A3A3A3;width:100%;height:auto;word-break:break-all; '>" + itemData.el.getAttribute('data-desc') + "</div>" + '</div>');
    else
	itemStr = itemStr.replace('{{content}}', '<div class="mui-slider-img-content">' + itemData.el.getAttribute("data-content") + "</br>" + '</div>');
} else
    itemStr = itemStr.replace('{{content}}', '');

3.给img标签添加属性

<img class="BoxDetailsImgItem" data-desc="款式:红锦满天星1000粒+肥+生根粉" data-content="已经收到了,谢谢" data-preview-src="" data-preview-group="1" src="img/photo.jpg" />
4.初始化图片预览插件:<script>mui.previewImage();</script>



扫描二维码关注公众号,回复: 3920926 查看本文章

猜你喜欢

转载自blog.csdn.net/qq_25027593/article/details/80000388
MUI