VUE 图片放大特效

源码:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>VUE 图片放大特效</title>
		<style>
			body {
			  margin: 0;
			  min-height: 100vh;
			  display: flex;
			  flex-direction: column;
			  align-items: center;
			  justify-content: center;
			  background-image: radial-gradient(circle, #fff 30%, #ccc);
			  padding: 0 40px;
			  font-family: "Source Sans Pro", Helvetica, sans-serif;
			  font-weight: 300;
			}
			#grid {
			  display: grid;
			  grid-template-columns: repeat(auto-fill, 150px);
			  grid-column-gap: 30px;
			  grid-row-gap: 30px;
			  align-items: center;
			  justify-content: center;
			  width: 100%;
			  max-width: 700px;
			}
			#grid .card {
			  background-color: #ccc;
			  width: 150px;
			  height: 150px;
			  transition: all 0.1s ease;
			  border-radius: 3px;
			  position: relative;
			  z-index: 1;
			  box-shadow: 0 0 5px rgba(0, 0, 0, 0);
			  overflow: hidden;
			  cursor: pointer;
			}
			#grid .card:hover {
			  -webkit-transform: scale(2);
			          transform: scale(2);
			  z-index: 2;
			  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
			}
			#grid .card:hover img {
			  -webkit-filter: grayscale(0);
			          filter: grayscale(0);
			}
			#grid .card .reflection {
			  position: absolute;
			  width: 100%;
			  height: 100%;
			  z-index: 2;
			  left: 0;
			  top: 0;
			  transition: all 0.1s ease;
			  opacity: 0;
			  mix-blend-mode: soft-light;
			}
			#grid .card img {
			  width: 100%;
			  height: 100%;
			  -o-object-fit: cover;
			     object-fit: cover;
			  -webkit-filter: grayscale(0.65);
			          filter: grayscale(0.65);
			  transition: all 0.3s ease;
			}
		</style>
	</head>
	<body>
		<div class="grid" id="grid">
			<photo-card img="img/1.jpg" link=""></photo-card>
			<photo-card img="img/2.jpg" link=""></photo-card>
			<photo-card img="img/3.jpg" link=""></photo-card>
			<photo-card img="img/4.jpg" link=""></photo-card>
			<photo-card img="img/5.jpg" link=""></photo-card>
			<photo-card img="img/6.jpg" link=""></photo-card>
			<photo-card img="img/7.jpg" link=""></photo-card>
			<photo-card img="img/8.jpg" link=""></photo-card>
		</div>
	</body>
	<script type="text/javascript" src="js/vue.min.js"></script>
	<script>
		Vue.component("photo-card", {
			template: `<a class="card"
			                :href="link"
			                target="_blank"
			                ref="card"
			                @mousemove="move"
			                @mouseleave="leave"
			                @mouseover="over">
			                  <div class="reflection" ref="refl"></div>
			                  <img :src="img"/>
			            </a>`,
			props: ["img", "link"],
			mounted() {},
			data: () => ({
				debounce: null
			}),
			methods: {
				over() {
						const refl = this.$refs.refl;
						refl.style.opacity = 1;
					},
				leave() {
					const card = this.$refs.card;
					const refl = this.$refs.refl;
					card.style.transform = `perspective(500px) scale(1)`;
					refl.style.opacity = 0;
				},
				move() {
					const card = this.$refs.card;
					const refl = this.$refs.refl;
					const relX = (event.offsetX + 1) / card.offsetWidth;
					const relY = (event.offsetY + 1) / card.offsetHeight;
					const rotY = `rotateY(${(relX - 0.5) * 60}deg)`;
					const rotX = `rotateX(${(relY - 0.5) * -60}deg)`;
					card.style.transform = `perspective(500px) scale(2) ${rotY} ${rotX}`;
					const lightX = this.scale(relX, 0, 1, 150, -50);
					const lightY = this.scale(relY, 0, 1, 30, -100);
					const lightConstrain = Math.min(Math.max(relY, 0.3), 0.7);
					const lightOpacity = this.scale(lightConstrain, 0.3, 1, 1, 0) * 255;
					const lightShade = `rgba(${lightOpacity}, ${lightOpacity}, ${lightOpacity}, 1)`;
					const lightShadeBlack = `rgba(0, 0, 0, 1)`;
					refl.style.backgroundImage = `radial-gradient(circle at ${lightX}% ${lightY}%, ${lightShade} 20%, ${lightShadeBlack})`;
				},
				scale: (val, inMin, inMax, outMin, outMax) =>
				outMin + (val - inMin) * (outMax - outMin) / (inMax - inMin)
			}
		});
		const app = new Vue({
			el: "#grid"
		});
	</script>
</html>

vue.min.js版本2.6.12

效果图:

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

豆皮没有豆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值