主要是mui.previewimage.js和mui.zoom.js的使用
image.png效果:
点开小图后(mui.zoom.js),会由小图缓冲放大
image.png放大后占满整个屏幕(或者是图片的宽度),并且可以用手指继续放大或者缩小查看:
image.png
经过缓冲加载后的图片左右滑动就是大图的形式:
image.png使用步骤:
(1)引入js文件
<script src="js/mui.min.js"></script>
<script src="js/mui.zoom.js"></script>
<script src="js/mui.previewimage.js"></script>
当然,mui.min.js离不开mui.min.css
<link href="css/mui.min.css" rel="stylesheet" />
(2)一段css样式代码(这个是必须的)
<style>
html,body {margin: 0px;padding: 0px;background-color: white;}
.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;
}
}
</style>
(3)需要小图预览的图片需要两个属性:data-preview-src(没有这个属性,Js无法抓取图片操作哦)和data-preview-group(设定为一个组的图片,一个组有多少图片,左上角数字显示就有多少)
![](images/06.jpg)
![](images/10.jpg)
![](images/17.jpg)
(4)在mui初始化后调用mui.previewImage()方法
<script type="text/javascript">
mui.init();
mui.previewImage();
</script>
** 总结:**
image.png image.png写个小demo还是灰常容易的呢,主要还是要学会分离项目,这个效果官方文档上并没有看到,后来在一个项目案例中发现有类似的效果,就抽取出来了,效果已经算很友好了,上手也很简单,做过安卓的画廊后发现web其实很多时候只要接触的东西多,一些框架,一些js了解一些,做东西就会快很多,所以还是要不断学习,不断接触一些新的技术知识,这样会省去很多实现起来的麻烦。
网友评论