<div class="flip-images"> <img src="./images/image_1.jpg"> <img src="./images/image_2.jpg"> <img src="./images/image_3.jpg"> </div> <a href="#" id='flip-one-more'>Flip</a>
var image_index = 0; // var images = parse_image_container(); function collect_images(){ var images = new Array(); $('.flip-images img').each(function(){ images.push($(this).attr('src')); $(this).remove(); }); return images; }
$('.flip-images').append("<div class='flip-container'>\ <div class='flip-top'>\ <div class='shadow-front'></div>\ <div class='front-image-top'></div>\ <div class='back-image-bottom'></div>\ <div class='shadow-back'></div>\ </div>\ <div class='back-image-top'></div>\ <div class='flip-bottom'>\ <div class='shadow-bottom'></div>\ <div class='front-image-bottom'></div>\ </div>\ </div>");
function place_images(){ var next_image_index = image_index+1; if(next_image_index==images.length){ next_image_index = 0; } var front_image = "<img src='"+images[image_index]+"'>"; var back_image = "<img src='"+images[next_image_index]+"'>"; $('.back-image-top').html("").append(back_image); $('.back-image-bottom').html("").append(back_image); $('.front-image-top').html("").append(front_image); $('.front-image-bottom').html("").append(front_image); }
.flip-images img{ width: 300px; height: 200px; } .flip-container{ width: 300px; height: 200px; position: relative; -webkit-perspective: 600px; } .flip-top{ height: 100px; overflow: hidden; width: 300px; } .flip-bottom{ position: relative; width: 300px; height: 100px; } /* */ .front-image-top{ /* */ display: block; -webkit-backface-visibility: hidden; /* */ position: absolute; top: 0px; width: 300px; height: 100px; /* , */ overflow: hidden; /* */ z-index: 900; } .front-image-bottom{ /* */ height: 100px; width: 300px; overflow: hidden; vertical-align: bottom; position: absolute; z-index: -2; } .front-image-bottom img{ position: absolute; top: -100px; /* , */ } /* */ .back-image-top{ height: 100px; position: absolute; top: 0px; vertical-align: top; overflow: hidden; z-index: -1; } .back-image-bottom{ display: block; position: absolute; top: 0px; height: 100px; -webkit-transform: rotateY(180deg) rotateZ(180deg); /* */ overflow: hidden; width: 300px; -webkit-backface-visibility: hidden; z-index: 800; } .back-image-bottom img{ position: absolute; top: -100px; } /**/ .shadow-top-front{ position: absolute; background: #000; z-index: 1000; width: 300px; height: 100px; -webkit-backface-visibility: hidden; opacity: 0; /* , */ } .shadow-top-back{ position: absolute; top: 0px; width: 300px; height: 100px; background: #000; z-index: 1000; -webkit-backface-visibility: hidden; -webkit-transform: rotateY(180deg); /* , */ opacity: 1; /* , */ } .shadow-bottom{ width: 300px; height: 100px; position: absolute; z-index: -1; background: #000; opacity: 0; }
@-webkit-keyframes flip { 0% { -webkit-transform: rotate3d(1,0,0, 0deg); } 50% { -webkit-transform: rotate3d(1,0,0, -180deg); } 60% { -webkit-transform: rotate3d(1,0,0, -155deg); } 70% { -webkit-transform: rotate3d(1,0,0, -140deg); } 100% { -webkit-transform: rotate3d(1,0,0, -180deg); } }
@-webkit-keyframes shadowTopFront{ 0% { opacity: 0; } 70% { opacity: 1; } 100% { opacity: 0; } } @-webkit-keyframes shadowTopBack { 0% { opacity: 0.8; } 50% { opacity: 0; } 60% { opacity: 0.05; } 70% { opacity: 0.1; } 100% { opacity: 0; } } @-webkit-keyframes shadowBottom { 0% { opacity: 0; } 50% { opacity: 0.6; } 60% { opacity: 0.4; } 70% { opacity: 0.3; } 100% { opacity: 0.5; } }
.flip { /*background: #ccc;*/ width: 200px; height: 100px; -webkit-transform-origin: bottom; -webkit-animation: flip 1s; /* */ -webkit-animation-iteration-count: 1; /* */ -webkit-animation-timing-function: cubic-bezier(0,0,1,0.5); /* */ -webkit-transform: rotate3d(1,0,0, 180deg); /* , 0 */ } .shadow-top-front-animate{ -webkit-animation: shadowTopFront 1s; -webkit-animation-iteration-count: 1; -webkit-animation-timing-function: cubic-bezier(0,0,1,0.5); opacity: 0; } .shadow-top-back-animate{ -webkit-animation: shadowTopBack 1s; -webkit-animation-iteration-count: 1; -webkit-animation-timing-function: cubic-bezier(0,0,1,0.5); opacity: 0; } .shadow-bottom-animate{ -webkit-animation: shadowBottom 1s; -webkit-animation-iteration-count: 1; -webkit-animation-timing-function: cubic-bezier(0,0,1,0.5); opacity: 1; }
$('#flip-one-more').click(function(){ place_images(image_index); $('.flip-top').addClass('flip'); $('.shadow-top-front').addClass('shadow-top-front-animate'); $('.shadow-top-back').addClass('shadow-top-back-animate'); $('.shadow-bottom').addClass('shadow-bottom-animate'); image_index = image_index + 1; if(image_index==images.length){ image_index = 0; } return false; });
$('#flip-one-more').click(function(){ flip_container = $('.flip-container'); new_flip_container = flip_container.clone(true); flip_container.before(new_flip_container); $("." + flip_container.attr("class") + ":last").remove(); place_images(); $('.flip-top').addClass('flip'); $('.shadow-top-front').addClass('shadow-top-front-animate'); $('.shadow-top-back').addClass('shadow-top-back-animate'); $('.shadow-bottom').addClass('shadow-bottom-animate'); image_index++; if(image_index==images.length){ image_index = 0; } return false; });
Source: https://habr.com/ru/post/140527/
All Articles