3D обложка с Parallax эффектом на jQuery
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
.btn { text-decoration: none; color: #fff; background: #AEBEC7; font-size: 12px; border-radius: 3px; padding: 10px; text-transform: uppercase; font-family: Helvetica Neue, Helvetica, Arial, sans-serif; box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); position: absolute; left: 50%; top: 75px; -webkit-transform: translateX(-50%); -ms-transform: translateX(-50%); transform: translateX(-50%); } .poster { width: 320px; height: 500px; position: absolute; top: 50%; left: 50%; margin: -250px 0 0 -160px; border-radius: 5px; box-shadow: 0 45px 100px rgba(0, 0, 0, 0.4); overflow: hidden; } .poster .shine { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: -webkit-linear-gradient(315deg, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0) 60%); background: linear-gradient(135deg, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0) 60%); z-index: 100; } .poster div[class*="layer-"] { position: absolute; top: -10px; left: -10px; right: -10px; bottom: -10px; background-size: 100% auto; background-repeat: no-repeat; background-position: 0 0; -webkit-transition: 0.1s; transition: 0.1s; } .poster .layer-1 { background-image: url("/images/1.png"); } .poster .layer-2 { background-image: url("/images/2.png"); } .poster .layer-3 { top: 0; bottom: 0; left: 0; right: 0; background-image: url("/images/3.png"); } .poster .layer-4 { background-image: url("/images/4.png"); } .poster .layer-5 { background-image: url("/images/5.png"); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
<script> /** * Designed by @Konstantine Trundayev * https://dribbble.com/k0t * Coded by @Balaj Marius for @Designmodo * http://mariusbalaj.com | http://designmodo.com */ var $poster = $('.poster'), $shine = $('.shine'), $layer = $('div[class*="layer-"]'), w = $(window).width(), //window width h = $(window).height(); //window height $(window).on('mousemove', function (e) { var offsetX = 0.5 - e.pageX / w, //cursor position X offsetY = 0.5 - e.pageY / h, //cursor position Y dy = e.pageY - h / 2, //@h/2 = center of poster dx = e.pageX - w / 2, //@w/2 = center of poster theta = Math.atan2(dy, dx), //angle between cursor and center of poster in RAD angle = theta * 180 / Math.PI - 90, //convert rad in degrees offsetPoster = $poster.data('offset'), transformPoster = 'translateY(' + -offsetX * offsetPoster + 'px) rotateX(' + (-offsetY * offsetPoster) + 'deg) rotateY(' + (offsetX * (offsetPoster * 2)) + 'deg)'; //poster transform //get angle between 0-360 if (angle < 0) { angle = angle + 360; } //gradient angle and opacity $shine.css('background', 'linear-gradient(' + angle + 'deg, rgba(255,255,255,' + e.pageY / h + ') 0%,rgba(255,255,255,0) 80%)'); //poster transform $poster.css('transform', transformPoster); //parallax foreach layer $layer.each(function () { var $this = $(this), offsetLayer = $this.data('offset') || 0, transformLayer = 'translateX(' + offsetX * offsetLayer + 'px) translateY(' + offsetY * offsetLayer + 'px)'; $this.css('transform', transformLayer); }); });</script> |
1 2 3 4 5 6 7 8 |
<div data-offset="5" class="poster"> <div class="shine"></div> <div data-offset="-2" class="layer-1"></div> <div class="layer-2"></div> <div data-offset="1" class="layer-3"></div> <div data-offset="3" class="layer-4"></div> <div data-offset="10" class="layer-5"></div> </div> |
Ууу, надо попробовать, если что отпишусь = )