JQ+Css3图片预览(旋转、缩放、切换)
$(function(){
//模拟数据图片
var data = [
'/material_thumb/',
'/material_thumb/',
'/material_thumb/',
'/material_thumb/',
'/material_thumb/'] //****图片地址必须放数组中
var _html = ''
var f = 0 ; R = 0 ; S = 1 ;i = 0 ; SS = 1
for(var i=0;i<data.length;i++){
_html += `<img style="width:200px;height:100px" src="${data[i]}">`
}
$('.showimg').html(_html)
//模拟数据图片
//点击查看预览
$('img').click(function(){
f = data.indexOf($(this).attr('src')) //获取点击预览的下标
R = 0
S = 1
i = 0
SS = 1
$('.imgstyle').css({'transform':"translate(-50% ,-50%) rotate("+R+"deg) scale("+SS+","+SS+")"})
$('.imgstyle').attr('src',data[f]) //显示框中img src 赋值
$('.toggleshow').toggle() //弹框显示隐藏
})
//左预览 ---
$('.left').click(function(){
if(f==0){
f=4
}else{
f--
}
$('.imgstyle').attr('src',data[f])
})
//右预览+++
$('.right').click(function(){
if(f==4){
f=0
}else{
f++
}
$('.imgstyle').attr('src',data[f])
})
//顺时针旋转
$('.rotateright').click(function(){
R += 90
$('.imgstyle').css({'transform':"translate(-50% ,-50%) rotate("+R+"deg) scale("+SS+","+SS+")"})
})
//逆时针旋转
$('.rotateleft').click(function(){
R -= 90
$('.imgstyle').css({'transform':"translate(-50% ,-50%) rotate("+R+"deg) scale("+SS+","+SS+")"})
})
//放大
$('.showbig').click(function(){
if(i>=0){
S++
i++
SS = 1*S
}else if(i<0){
S--
i++
SS = 1/S
}
$('.imgstyle').css({'transform':"translate(-50% ,-50%) rotate("+R+"deg) scale("+SS+","+SS+")"})
})
//缩小
$('.showmin').click(function(){
if(i<=0){
i--
S++
SS = 1/S
}else{
i--
S--
SS = 1*S
}
$('.imgstyle').css({'transform':"translate(-50% ,-50%) rotate("+R+"deg) scale("+SS+","+SS+")"})
})
// 点击X 或者黑背景关闭
$('.dilong , .close').click(function(){
$('.toggleshow').toggle()
})
})