html+css+js三维倾斜3D效果悬停

<div class="card">
  <div class="card-content">
    <h1>Just hover around</h1>
    <p><small>by  Ariona, Rian </small></p>
    <p class="related"><strong>See also: </strong> Staged dropdown animation </p>
    
  </div>
</div>
@import url(http://fonts.googleapis.com/css?family=Playfair+Display:400,400italic,700);
body {
  background: #edf2f4;
  -webkit-perspective: 1000px;
          perspective: 1000px;
  -webkit-transform-style: preserve-3d;
          transform-style: preserve-3d;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  height: 100vh;
  font-family: "Playfair Display",georgia,serif;
}

.card {
  pointer-events: none;
  -webkit-transform: translateZ(0);
          transform: translateZ(0);
  padding: 30px;
  background: white;
  border-radius: 5px;
  width: 400px;
  height: 200px;
  margin: auto;
  -webkit-transform-style: preserve-3d;
          transform-style: preserve-3d;
  -webkit-backface-visibility: hidden;
          backface-visibility: hidden;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
  position: relative;
}
.card:after {
  content: " ";
  position: absolute;
  width: 100%;
  height: 10px;
  border-radius: 50%;
  left: 0;
  bottom: -50px;
  box-shadow: 0 30px 20px rgba(0, 0, 0, 0.3);
}
.card .card-content {
  margin: auto;
  text-align: center;
  -webkit-transform-style: preserve-3d;
          transform-style: preserve-3d;
}
.card h1 {
  -webkit-transform: translateZ(100px);
          transform: translateZ(100px);
}
.card p {
  -webkit-transform: translateZ(50px);
          transform: translateZ(50px);
  display: block;
}
.card p.related {
  -webkit-transform: translateZ(80px);
          transform: translateZ(80px);
  font-style: italic;
}
.card a {
  color: #69c6b8;
  pointer-events: auto;
}
var card = $(".card");

$(document).on("mousemove", function(e) {
  var ax = -($(window).innerWidth() / 2 - e.pageX) / 20;
  var ay = ($(window).innerHeight() / 2 - e.pageY) / 10;
  card.attr("style", "transform: rotateY(" + ax + "deg) rotateX(" + ay + "deg);-webkit-transform: rotateY(" + ax + "deg) rotateX(" + ay + "deg);-moz-transform: rotateY(" + ax + "deg) rotateX(" + ay + "deg)");
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TweenMax.min.js"></script>
<div class="wrapper">
	
	<div class="panel">
		<div class="panel__content-col">
			<div class="panel__content">
				<div class="panel__text">
					<h1 class="panel__title">Tap House</h1>
					<p class="panel__addr"><span></span>60 Ranelagh Village, Dublin</p>
				</div>
				<div class="panel__line"></div>
			</div>
		</div>
		<div class="panel__img-col">
			<img src="http://www.jq22.com/tp/8fbde47e-0501-4cc9-92f4-0402278df9c8.jpg" alt="" class="panel__img">
		</div>
	</div>
	
</div>
html {
  box-sizing: border-box;
}

*, *:before, *:after {
  box-sizing: inherit;
}

html, body {
  width: 100%;
  height: 100%;
}

body {
  background-color: #292929;
  color: white;
  font-size: 18px;
  -webkit-font-feature-settings: "kern" 1,"liga" 1,"frac" 1, "lnum" 1;
          font-feature-settings: "kern" 1,"liga" 1,"frac" 1, "lnum" 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1 {
  font-family: 'Playfair Display', serif;
  font-size: 96px;
}

p {
  font-family: 'Lato', sans-serif;
}

.wrapper {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  width: 100%;
  height: 100%;
  padding: 5vh 5%;
}

.panel {
  position: relative;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  width: 100%;
  max-width: 1200px;
  height: 466px;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
  pointer-events: none;
}

.panel__content-col {
  -ms-flex-preferred-size: 25%;
      flex-basis: 25%;
}

.panel__content {
  position: absolute;
  top: 26%;
  left: 0;
  z-index: 2;
  width: 100%;
}

.panel__text {
  display: inline-block;
  text-align: right;
}

.panel__img-col {
  -ms-flex-preferred-size: 70%;
      flex-basis: 70%;
  box-shadow: 0px 20px 100.28px 8.72px rgba(0, 0, 0, 0.35);
}

.panel__title {
  margin: 0;
}

.panel__addr {
  position: relative;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  margin: 16px 0 0;
  -webkit-box-pack: end;
      -ms-flex-pack: end;
          justify-content: flex-end;
}
.panel__addr span {
  display: block;
  margin: 9px 14px 0 0;
  height: 1px;
  width: 30px;
  background-color: #fff;
}

.panel__line {
  width: 64%;
  height: 3px;
  margin: 24px 0 0 36%;
  background-color: #fff;
}

.panel__img-col {
  width: 100%;
}

.panel__img {
  display: block;
  width: 100%;
  height: 100%;
  -o-object-fit: cover;
     object-fit: cover;
}
var $body = $("body"),
	$panel = $(".panel"),
	$pContent = $(".panel__content"),
	$img = $(".panel__img-col");
var $body = $("body"),
	$panel = $(".panel"),
	$pContent = $(".panel__content"),
	$img = $(".panel__img-col");

function initTilt() {
	TweenMax.set([$pContent, $img], { transformStyle: "preserve-3d" });

	$body.mousemove(function(e) {
		var sxPos = e.pageX / $panel.width() * 100 - 100;
		var syPos = e.pageY / $panel.height() * 100 - 100;
		TweenMax.to($pContent, 2, {
			rotationY: 0.03 * sxPos,
			rotationX: -0.03 * syPos,
			transformPerspective: 500,
			transformOrigin: "center center -400",
			ease: Expo.easeOut
		});
		TweenMax.to($img, 2, {
			rotationY: 0.03 * sxPos,
			rotationX: -0.03 * syPos,
			transformPerspective: 500,
			transformOrigin: "center center -200",
			ease: Expo.easeOut
		});
	});
}

initTilt();

console.clear();

function initTilt() {
	TweenMax.set([$pContent, $img], { transformStyle: "preserve-3d" });

	$body.mousemove(function(e) {
		var sxPos = e.pageX / $panel.width() * 100 - 100;
		var syPos = e.pageY / $panel.height() * 100 - 100;
		TweenMax.to($pContent, 2, {
			rotationY: 0.03 * sxPos,
			rotationX: -0.03 * syPos,
			transformPerspective: 500,
			transformOrigin: "center center -400",
			ease: Expo.easeOut
		});
		TweenMax.to($img, 2, {
			rotationY: 0.03 * sxPos,
			rotationX: -0.03 * syPos,
			transformPerspective: 500,
			transformOrigin: "center center -200",
			ease: Expo.easeOut
		});
	});
}

initTilt();

console.clear();

 

 

未经允许不得转载:乔越博客 » html+css+js三维倾斜3D效果悬停

赞 (6) 打赏

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. 12222alert(1)回复

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏