image change preview

<style type="text/css">
#idNum {
position: absolute;
right: 424px;
top:447px;
bottom: -1px !important;
bottom: 65px;
}

#idNum li {
float: left;
list-style: none;
color: #fff;
text-align: center;
line-height: 16px;
width: 16px;
height: 16px;
font-family: Arial;
font-size: 12px;
cursor: pointer;
margin: 1px;
border: 1px solid #707070;
background-color: #060a0b;
}

#idNum li.on {
line-height: 18px;
width: 18px;
height: 18px;
font-size: 14px;
border: 0;
background-color: #ce0609;
font-weight: bold;
}
</style>


<div id="idPicShow">
<ul id="idNum">
</ul>
</div>
<div id="idPicText" style="display: none"></div>
<div id="idPicList" style="display: none"></div>
<script>


var isIE = (document.all) ? true : false;

var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};

var Class = {
create: function() {
return function() { this.initialize.apply(this, arguments); }
}
}

var Extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
}

var Bind = function(object, fun) {
return function() {
return fun.apply(object, arguments);
}
}

var Each = function(list, fun){
for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
};


//ie only
var RevealTrans = Class.create();
RevealTrans.prototype = {
initialize: function(container, options) {
this._img = document.createElement("img");
this._a = document.createElement("a");

this._timer = null;//计时器
this.Index = 0;//显示索引
this._onIndex = -1;//当前索引

this.SetOptions(options);

this.Auto = !!this.options.Auto;
this.Pause = Math.abs(this.options.Pause);
this.Duration = Math.abs(this.options.Duration);
this.Transition = parseInt(this.options.Transition);
this.List = this.options.List;
this.onShow = this.options.onShow;

//初始化显示区域
this._img.style.visibility = "hidden";//第一次变换时不显示红x图
this._img.style.border = 0;
this._img.onmouseover = Bind(this, this.Stop);
this._img.onmouseout = Bind(this, this.Start);
isIE && (this._img.style.filter = "revealTrans()");

this._a.target = "_blank";

$(container).appendChild(this._a).appendChild(this._img);
},
//设置默认属性
SetOptions: function(options) {
this.options = {//默认值
Auto: true,//是否自动切换
Pause: 3000,//停顿时间(微妙)
Duration: 1,//变换持续时间(秒)
Transition: 23,//变换效果(23为随机)
List: [],//数据集合,如果这里不设置可以用Add方法添加
onShow: function(){}//变换时执行
};
Extend(this.options, options || {});
},
Start: function() {
clearTimeout(this._timer);
//如果没有数据就返回
if(!this.List.length) return;
//修正Index
if(this.Index < 0 || this.Index >= this.List.length){ this.Index = 0; }
//如果当前索引不是显示索引就设置显示
if(this._onIndex != this.Index){ this._onIndex = this.Index; this.Show(this.List[this.Index]); }
//如果要自动切换
if(this.Auto){
this._timer = setTimeout(Bind(this, function(){ this.Index++; this.Start(); }), this.Duration * 1000 + this.Pause);
}
},
//显示
Show: function(list) {
if(isIE){
//设置变换参数
with(this._img.filters.revealTrans){
Transition = this.Transition; Duration = this.Duration; apply(); play();
}
}
this._img.style.visibility = "";
//设置图片属性
this._img.src = list.img; this._img.alt = list.text;
//设置链接
!!list["url"] ? (this._a.href = list["url"]) : this._a.removeAttribute("href");
//附加函数
this.onShow();
},
//添加变换对象
Add: function(sIimg, sText, sUrl) {
this.List.push({ img: sIimg, text: sText, url: sUrl });
},
//停止
Stop: function() {
clearTimeout(this._timer);
}
};


//////////////////////

var rvt = new RevealTrans("idPicShow");

//添加变换对象
rvt.Add('<%=path%>/story/image/banner.gif', '', 'http://www.jianlibao.com.cn/lalaevent/lala-index.asp');
rvt.Add('./images/index_roll_2.jpg', '', 'http://www.16zg.com/readDetailNews.action?newsId=2c90e0c422209304012220d609920022');
//rvt.Add('./images/index_roll_3.jpg', '', 'http://angel.2010angel.com');
rvt.Add('./images/index_roll_4.jpg', '', 'http://www.rayli.com.cn/region/C0073.html');
//rvt.Add('./images/index_roll_5.jpg', '', '');

var oList = $("idPicList"), oText = $("idPicText"), arrImg = [];

var oNum = $("idNum"), arrNum = [];

//设置图片列表
Each(rvt.List, function(list, i){
//图片式
var img = document.createElement("img");
img.src = list["img"]; img.alt = list["text"];
arrImg[i] = img;
oList.appendChild(img);
//按钮式
var li = document.createElement("li");
li.innerHTML = i + 1;
arrNum[i] = li;
oNum.appendChild(li);
//事件设置
img.onmouseover = li.onmouseover = function(){ rvt.Auto = false; rvt.Index = i; rvt.Start(); };
img.onmouseout = li.onmouseout = function(){ rvt.Auto = true; rvt.Start(); };
});

//设置图片列表样式 文本显示区域
rvt.onShow = function(){
var i = this.Index, list = this.List[i];
//图片式
Each(arrImg, function(o){ o.className = ""; }); arrImg[i].className = "on";
//按钮式
Each(arrNum, function(o){ o.className = ""; }); arrNum[i].className = "on";
//文本区域
oText.innerHTML = !!list.url ? "<a href='" + list.url + "' target='_blank'>" + list.text + "</a>" : list.text;
}

//文本显示区域
oText.onmouseover = function(){ rvt.Auto = false; rvt.Stop(); };
oText.onmouseout = function(){ rvt.Auto = true; rvt.Start(); };

rvt.Start();
</script>
`uView UI` 的 `<u-image-preview>` 组件是一个封装好的 Vue 组件,其源码是开源的,托管在 GitHub 上。它主要基于 Vue 2 或 Vue 3 实现,适配了 UniApp 的多平台特性(如微信小程序、H5、App 等)。 --- ## 🔍 官方源码地址(GitHub) 你可以访问 uView 官方仓库查看 `<u-image-preview>` 的源码: 👉 [uView UI GitHub 仓库](https://github.com/umicro/uView) 具体组件源码路径(Vue 2): 👉 [uView 2.x - u-image-preview 源码](https://github.com/umicro/uView/blob/2.0.34/components/u-image-preview/u-image-preview.vue) --- ## 📦 `<u-image-preview>` 主要功能 这个组件实现了以下功能: - 图片预览(支持多张) - 支持缩放(手势缩放) - 支持滑动切换 - 支持点击关闭 - 支持长按保存图片(部分平台) - 支持自定义背景、关闭按钮等 --- ## 📄 示例源码(简化版) 下面是 `<u-image-preview>` 的简化版核心代码(基于 Vue 2 和 UniApp 语法): ```vue <template> <view v-if="show" class="u-image-preview" @touchmove.stop.prevent> <!-- 背景遮罩 --> <view class="u-image-preview__mask" @click="close"></view> <!-- 图片容器 --> <swiper class="u-image-preview__swiper" :current="currentIndex" @change="swiperChange" > <swiper-item v-for="(url, index) in urls" :key="index"> <image class="u-image-preview__image" :src="url" mode="aspectFit" @tap="toggleCloseBtn" /> </swiper-item> </swiper> <!-- 关闭按钮 --> <view v-if="closeable && showCloseBtn" class="u-image-preview__close" @click="close">×</view> </view> </template> <script> export default { name: 'u-image-preview', props: { // 是否显示组件 show: { type: Boolean, default: false }, // 图片地址列表 urls: { type: Array, default: () => [] }, // 当前显示的图片索引 current: { type: Number, default: 0 }, // 是否显示关闭按钮 closeable: { type: Boolean, default: true } }, data() { return { currentIndex: this.current, showCloseBtn: true } }, watch: { show(val) { if (!val) { this.showCloseBtn = true } } }, methods: { // 切换 swiper 时更新当前索引 swiperChange(e) { this.currentIndex = e.detail.current }, // 关闭预览 close() { this.$emit('close') this.$emit('input', false) }, // 切换关闭按钮显示 toggleCloseBtn() { this.showCloseBtn = !this.showCloseBtn } } } </script> <style scoped> .u-image-preview { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; } .u-image-preview__mask { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.7); } .u-image-preview__swiper { width: 100%; height: 100%; } .u-image-preview__image { width: 100%; height: 100%; } .u-image-preview__close { position: absolute; top: 20px; right: 20px; color: #fff; font-size: 28px; } </style> ``` --- ## ✅ 总结 | 特性 | 说明 | |------|------| | 开源 | 是,GitHub 可查看 | | 支持平台 | UniApp 所有平台(小程序、H5、App) | | 功能 | 支持缩放、滑动、关闭、自定义等 | | 源码结构 | 基于 Vue + UniApp 组件封装 | ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值