"card"
Bootstrap 3.0.0 Snippet by evarevirus

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <!DOCTYPE html><html class=''> <head><script src='//production-assets.codepen.io/assets/editor/live/console_runner-079c09a0e3b9ff743e39ee2d5637b9216b3545af0de366d4b9aad9dc87e26bfd.js'></script><script src='//production-assets.codepen.io/assets/editor/live/events_runner-73716630c22bbc8cff4bd0f07b135f00a0bdc5d14629260c3ec49e5606f98fdd.js'></script><script src='//production-assets.codepen.io/assets/editor/live/css_live_reload_init-2c0dc5167d60a5af3ee189d570b1835129687ea2a61bee3513dee3a50c115a77.js'></script><meta charset='UTF-8'><meta name="robots" content="noindex"><link rel="shortcut icon" type="image/x-icon" href="//production-assets.codepen.io/assets/favicon/favicon-8ea04875e70c4b0bb41da869e81236e54394d63638a1ef12fa558a4a835f1164.ico" /><link rel="mask-icon" type="" href="//production-assets.codepen.io/assets/favicon/logo-pin-f2d2b6d2c61838f7e76325261b7195c27224080bc099486ddd6dccb469b8e8e6.svg" color="#111" /><link rel="canonical" href="https://codepen.io/oneplusuniverse/pen/MJrabj?depth=everything&order=popularity&page=63&q=mobile&show_forks=false" /> <style class="cp-pen-styles">@import url(https://fonts.googleapis.com/css?family=Great+Vibes); body { margin: 0; padding: 0; background: #B0DAB9; background: linear-gradient(to left, #DAD299, #B0DAB9); } body:before { z-index: -999; position: absolute; display: block; left: 0; right: 0; top: 2vh; text-align: center; content: 'Hover or Tilt (mobile devices only)'; font-size: 50px; text-shadow: 1px 3px 5px rgba(0, 0, 0, 0.3); font-family: 'Great Vibes', cursive; color: rgba(255, 255, 255, 0.8); transition: 0.6s cubic-bezier(0.25, 1, 0.1, 1); } @media (max-width: 500px) { body:before { content: ''; } } html { height: 100vh; } html::-webkit-scrollbar-track { background-color: #ddd6f3; } html::-webkit-scrollbar { width: 8px; padding-right: 1px; } html::-webkit-scrollbar-thumb { background-color: #8fbcbb; border-radius: 1px; } /* HEADER */ .header { visibility: hidden; position: relative; display: inline-block; left: 5%; width: 105px; height: 40px; background: rgba(33, 33, 33, 0.62); border-radius: 0 0 10px 10px; } @media (max-width: 500px) { .header { visibility: visible; } .header:after { z-index: -999; position: absolute; display: block; top: 10px; left: 110px; width: 60vw; height: 40px; text-align: center; content: 'Tilt (mobile devices only)'; font-size: 1.5em; font-family: 'Great Vibes', cursive; color: rgba(255, 255, 255, 0.9); transition: 0.6s cubic-bezier(0.25, 1, 0.1, 1); } } .tilt { border-radius: 2px; background-color: #999; display: inline-block; position: relative; left: 52px; width: 30px; height: 20px; transform: perspective(30px) rotateY(0deg); transition: 0.6s cubic-bezier(0.25, 1, 0.1, 1); } .switch { position: relative; display: inline-block; margin: 10px; width: 40px; height: 20px; } .switch input { display: none; } .switch input:checked + .slider { background-color: #8ba6fd; } .switch input:checked ~ .tilt { transform: perspective(30px) rotateY(20deg); } .switch input:focus + .slider { box-shadow: 0 0 1px #2196F3; } .switch input:checked + .slider:before { background-color: white; -webkit-transform: translateX(18px); -ms-transform: translateX(18px); transform: translateX(18px); } .switch .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(255, 255, 255, 0.3); -webkit-transition: .4s; transition: .4s; } .switch .slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 2px; background-color: rgba(255, 255, 255, 0.5); -webkit-transition: .4s; transition: .4s; } .switch .slider.round { border-radius: 34px; } .switch .slider.round:before { border-radius: 50%; } /* CONTENT: */ .wrapper { padding: 40px 80px; display: flex; flex-wrap: wrap; justify-content: center; } .card { display: inline-block; transform: perspective(800px); transform-style: preserve-3d; border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.3); background-color: #222; overflow: hidden; cursor: pointer; margin: 20px auto 20px auto; width: 250px; height: 352px; max-width: 100%; max-height: 100%; box-shadow: rgba(0, 0, 0, 0.5) 0 30px 40px 0, inset #222 0 0 0 5px; transition: 0.6s cubic-bezier(0.25, 1, 0.1, 1); } .card-background { overflow: hidden; position: relative; top: -10%; left: -10%; width: 120%; height: 120%; padding: 5%; background-repeat: no-repeat; background-position: center; background-size: cover; transition: 0.6s cubic-bezier(0.25, 1, 0.1, 1); } </style></head><body> <div class="header"> <label class="switch" for="mobileTilt"> <input type="checkbox" checked="checked" id="mobileTilt"/> <div class="slider round"></div> <div class="tilt"></div> </label> </div> <div class="wrapper"> <div class="card" id="card"> <div class="card-background" id="cardBg" style="background-image:url('https://res.cloudinary.com/dvabjvqjl/raw/upload/v1485734039/Grebz/pine-1884335_1280.jpg')"></div> </div> <div class="card" id="card1"> <div class="card-background" id="cardBg1" style="background-image:url('https://res.cloudinary.com/dvabjvqjl/raw/upload/v1486256993/Grebz/shoes-1638873_1920.jpg')"></div> </div> </div> <script src='//production-assets.codepen.io/assets/common/stopExecutionOnTimeout-b2a7b3fe212eaa732349046d8416e00a9dec26eb7fd347590fbced3ab38af52e.js'></script> <script >document.addEventListener("DOMContentLoaded", ready); var cardW = 250; var cardH = 352; var hcardW = cardW / 2; var hcardH = cardH / 2; function openInNewTab(url) { var win = window.open(url, '_blank'); win.focus(); } function ready() { /* *Gyro */ if(window.DeviceMotionEvent){ window.ondevicemotion = function(event) { var accelerationX = event.accelerationIncludingGravity.x; var accelerationY = event.accelerationIncludingGravity.y; var xOff = accelerationX * 3; var yOff = -accelerationY * 3; var mobileTilt = document.getElementById("mobileTilt"); animateMobile(document.getElementById('card'), document.getElementById('card').children[0], xOff, yOff, mobileTilt, accelerationX, accelerationY); animateMobile(document.getElementById('card1'), document.getElementById('card1').children[0], xOff, yOff, mobileTilt, accelerationX, accelerationY); } } animate(document.getElementById('card')); animate(document.getElementById('card1')); // demo(); } function animate(card) { var cardBg = card.children[0]; card.addEventListener("click", function() { openInNewTab('https://codepen.io/oneplusuniverse/'); }); card.addEventListener("mousemove", function(event) { card.style.transition = ''; //image offset var xOff = -(event.offsetX - hcardW) * 0.1; var yOff = -(event.offsetY - hcardH) * 0.1; //tilt card var xTilt = (event.offsetX - hcardW) / 20; var yTilt = -(event.offsetY - hcardH) / 20; cardBg.style.transform = 'translateX(' + xOff + 'px) translateY(' + yOff + 'px)'; card.style.transform = 'perspective(500px) rotateY( ' + xTilt + 'deg) rotateX( ' + yTilt + 'deg)'; }); card.addEventListener("mouseleave", function() { setTimeout(() => { card.style.transition = ' 0.5s'; cardBg.style.transform = 'translateX(0px) translateY(0px)'; card.style.transform = 'perspective(500px) rotateY( 0deg) rotateX( 0deg)'; }, 500); }); } function animateMobile(card, cardBg, xOff, yOff, mobileTilt, accelerationX, accelerationY) { cardBg.style.transform = 'translateX(' + xOff + 'px) translateY(' + yOff + 'px)'; if (mobileTilt.checked) { card.style.transform = 'perspective(500px) rotateY( ' + accelerationX * 2 + 'deg) rotateX( ' + accelerationY * 2 + 'deg) '; } else { card.style.transform = 'perspective(500px) rotateY( 0deg) rotateX( 0deg)'; } } /* * Demo */ function demo() { // veeeeery ugly demo, but I haven't much time. var interval = 300; setTimeout(() => { cardBg.style.transform = 'translateX(10px) translateY(0px)'; card.style.transform = 'perspective(500px) rotateY( -5deg) rotateX( 0deg)'; }, interval * 1); setTimeout(() => { cardBg.style.transform = 'translateX(5px) translateY(7.5px)'; card.style.transform = 'perspective(500px) rotateY( -2.5deg) rotateX( 3.5deg)'; }, interval * 2); setTimeout(() => { cardBg.style.transform = 'translateX(0px) translateY(15px)'; card.style.transform = 'perspective(500px) rotateY( 0deg) rotateX( 7deg)'; }, interval * 3); setTimeout(() => { cardBg.style.transform = 'translateX(-5px) translateY(7.5px)'; card.style.transform = 'perspective(500px) rotateY( 2.5deg) rotateX( 3.5deg)'; }, interval * 4); setTimeout(() => { cardBg.style.transform = 'translateX(-10px) translateY(0px)'; card.style.transform = 'perspective(500px) rotateY( 5deg) rotateX( 0deg)'; }, interval * 5); setTimeout(() => { cardBg.style.transform = 'translateX(-5px) translateY(-7.5px)'; card.style.transform = 'perspective(500px) rotateY( 2.5deg) rotateX( -3.5deg)'; }, interval * 6); setTimeout(() => { cardBg.style.transform = 'translateX(0px) translateY(-15px)'; card.style.transform = 'perspective(500px) rotateY( 0deg) rotateX( -7deg)'; }, interval * 7); setTimeout(() => { cardBg.style.transform = 'translateX(0px) translateY(-7.5px)'; card.style.transform = 'perspective(500px) rotateY( 0deg) rotateX( 0deg)'; }, interval * 8); } //# sourceURL=pen.js </script> </body></html>

Related: See More


Questions / Comments: