实现淘宝的这个功能
实现功能是点击淘宝的图片可以放大,继续轮播.
js+html
主要js
css就不放图片了,其实实现的方式就是用层级,z-index. 我主要用了swiper.
就直接把代码放上了.记得引入swiper.css和swiper.js.我使用的是zepto.js,其实跟jq没什么区别,引入哪一个都可以
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta content="telephone=no" name="format-detection" />
<title>Document</title>
<link rel="stylesheet" href="./css/swiper.min.css">
<script src="./js/zepto.min.js"></script>
<script src="./js/swiper.min.js"></script>
<script>
// 字体
document.documentElement.style.fontSize = document.documentElement.clientWidth / 6.4 + "px";
</script>
<style>
body,
html {
padding: 0;
margin: 0;
}
img {
border: 0;
vertical-align: middle;
width: 100%;
}
.supply_cons_luns .swiper-pagination {
background: #858585;
width: auto;
height: auto;
border-radius: 15px;
text-align: center;
font-size: 0.16rem;
color: #FFFFFF;
left: auto;
right: 14px;
padding: 2px 0.1rem;
}
.all_big_fixed {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #000;
z-index: 2;
display: none;
}
.supply_cons_luns .ons {
z-index: 4;
overflow: inherit;
}
.lun_onss {
height: 6.4rem;
z-index: 5;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
.supply_cons_luns .ons2 .swiper-pagination-current {
font-size: 0.52rem;
margin-right: -4px
}
.supply_cons_luns .ons2 {
top: -1rem;
bottom: auto;
background: none;
color: #b0b0b0;
font-size: 0.4rem;
font-family: 'Arial';
}
.all_gig_zou {
width: 0.42rem;
margin: 0.6rem 0 0 14px;
display: none;
}
</style>
<script>
$(function () {
$(".all_big_guan").click(function () {
$(".all_big_guan").hide();
$(".all_gig_zou").hide();
$(".supply_cons_luns").find(".swiper-container").removeClass("ons");
$(".supply_cons_luns").removeClass("lun_onss");
$(".supply_cons_luns").find(".swiper-pagination").removeClass("ons2");
})
$(".supply_cons_luns .swiper-slide img").click(function () {
$(".all_big_guan").show();
$(".all_gig_zou").show();
$(".supply_cons_luns").find(".swiper-container").addClass("ons");
$(".supply_cons_luns").addClass("lun_onss");
$(".supply_cons_luns").find(".swiper-pagination").addClass("ons2");
})
})
</script>
</head>
<body>
<main>
<!-- 轮播 -->
<div class="supply_cons_luns">
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<img src="./page1.jpg" alt="">
</div>
<div class="swiper-slide">
<img src="./page1.jpg" alt="">
</div>
<div class="swiper-slide">
<img src="./page1.jpg" alt="">
</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
</div>
</div>
</main>
<!-- 图片轮播 -->
<div class="all_big_fixed all_big_guan"></div>
<script>
var swiper = new Swiper('.supply_cons_luns .swiper-container', {
pagination: {
el: '.swiper-pagination',
type: 'fraction',
}
});
</script>
</body>
</html>
放上我自己写出来的效果
完美兼容手机端
网友评论