Flip and Grow Google Maps Effect

I did some research on how to create a flip and growth effect, like a Google map does (click on any map):

http://www.google.com/landing/now/#cards/restaurant-reservations

All the resources that I have found are flipping the cards in front and back of the same size, but this is not what I'm looking for.

Any feedback would be greatly appreciated.

+6
source share
4 answers

your code is here! clickFLIPgrove

You can scale the size of the div property with css called transformations: scale (2,2); it will double the size of your element link to this link for all css effects: cssAnimation

I created a flip effect on hover:

hoverFLIP

HTML


<div class="cards"></div> 

CSS


  body{ position: relative; } .cards{ margin:30px; perspective: 500; -webkit-perspective: 500; -moz-perspective: 500; -ms-perspective: 500; -o-perspective: 500; width:200px; height:200px; background-color:#59A3FF; transform-style:preserve-3d; -webkit-transform-style:preserve-3d; -moz-transform-style:preserve-3d; -o-transform-style:preserve-3d; position:absolute; cursor:pointer; /* Animate the transitions */ -webkit-transition:0.8s; text-align:center; -moz-transition:0.8s; text-align:center; -ms-transition:0.8s; text-align:center; -o-transition:0.8s; text-align:center; transition:0.8s; text-align:center; } .flip{ transform:rotateY(180deg) scale(1.2,1.2); -webkit-transform:rotateY(180deg) scale(1.2,1.2); -moz-transform:rotateY(180deg); -o-transform:rotateY(180deg); -ms-transform:rotateY(180deg); background-color:#FF5959; } 

javascript (add jQuery 2.1.0)


  $(".cards").click(function(){ $(this).toggleClass("flip"); }); 
+5
source

Both of the answers posted here are good universal css flippers, but they don’t touch on the core of the question, β€œHow does Google do this?” The problem is that google minimizes and therefore confuses their code, which makes it difficult to say exactly what is happening, but with the help of the DOM inspector, you can get a pretty basic idea. This is an abstract:

  • Create a div with "clone" that contains the front and back child divs but is hidden by default. Set its css transition property to ~ .5seconds so that any movement of it is animated.
  • When the user clicks on the map in the grid, set the clone so that it is the same position / size, like a clicked map, copy the contents of the clicked map to the front child element and set it as visible
  • Hide original clickable map with visibility: hidden
  • At the moment, you now have a clone of the originally clicked card in the same place, but no one can tell
  • Set the css for the top, left, height, width of the clone div to the pre-calculated sizes, centering on the screen, and also set the conversion: rotateY () of the front / rear children
  • At this point, it seems that the div rises, flips and moves / changes to the center of the screen. The empty space is left behind because the original map is still there, but visibility: hidden allows it to take up space without showing its contents
  • The click handler is configured so that when the user clicks outside the clone map, top, left, height, width, conversion: rotateY () css reset returns to the original values, which cause it to return back in place.
  • Then the clone disappears again, and the original map becomes visible.

Demo: http://jsfiddle.net/jwhazel/AaU6v/11/

(Developed in Chrome may require some vendor prefixes for other browsers)

HTML


  <div class="cards">Generic Tile Card</div> <div id="cardClone"> <div id="cloneFront">cardclone front</div> <div id="cloneBack">cardclone back</div> </div> 

CSS


 body { position: relative; font-family:Helvetica, Arial, Sans-serif; text-align:center; } .cards { margin:30px; width:200px; height:200px; background-color:#59A3FF; cursor:pointer; display:inline-block; overflow:hidden; } img { display:block; width:80%; height:auto; margin:0 auto } #cardClone { position:fixed; display:none; margin:30px; width:200px; height:200px; -webkit-transition:.6s; transition:.6s; -webkit-transform-style::preserve-3d; transform-style:preserve-3d; z-index:99; perspective: 1000px; -webkit-perspective: 1000px; } #cloneFront, #cloneBack { backface-visibility: hidden; width:100%; height:100%; position:absolute; -webkit-transition:.6s; transition:.6s; overflow:hidden; } #cloneFront { z-index:100; background-color:#59A3FF; transform: translatez(0); } #cloneBack { transform:rotateY(-180deg); z-index:101; background-color:#aaa; } 

Javascript


 //Cache the clone since we have to select it a couple of times $clone = $('#cardClone'); //Set a global for the card we just clicked so we can track it $lastelement = ""; //Set up an object for last clicked element so we know where to return to on collapse lastelement = { 'top': 0, 'left': 0, 'width': 0, 'height': 0 }; //Set a flag to determine the current flip state of our clone cloneflipped = false; //Bind a handler to the clone so we can detect when the transition is done $('#cardClone').on("transitionend", function (e) { if (e.target === e.currentTarget) { if (e.originalEvent.propertyName == 'top') { //Toggle the clone state cloneflipped = !cloneflipped; //Detect if our clone has returned to the original position and then hide it if (!cloneflipped) { $($lastelement).css('opacity', 1); $($clone).hide(); } else { //Need to dynamically alter contents of the clone rear AFTER it animates? Do it here //$('#cloneBack').html('hi'); } } } }); $(".cards").click(function () { if (!cloneflipped) { //Cache clicked card $lastelement = $(this); //Store position of this element for the return trip //[hack: subtract 30 due to the margin of .cards in this demo] var offset = $lastelement.offset(); lastelement.top = offset.top - 30 - $(document).scrollTop(); lastelement.left = offset.left - 30; lastelement.width = $lastelement.width(); lastelement.height = $lastelement.height(); //BONUS: lets check to see if the clicked card is further to the left or the right of the screen //This way we can make the animation rotate inwards toward the center, google doesn't do this var rotatefront = "rotateY(180deg)"; var rotateback = "rotateY(0deg)"; if ((lastelement.left + lastelement.width / 2) > $(window).width() / 2) { rotatefront = "rotateY(-180deg)"; rotateback = "rotateY(-360deg)"; } //Copy contents of the clicked card into the clones front card $clone.find('#cloneFront').html($lastelement.html()); //Show the clone on top of the clicked card and hide the clicked card //[hack: using opacity for hiding here, visibility:hidden has a weird lag in win chrome] $clone.css({ 'display': 'block', 'top': lastelement.top, 'left': lastelement.left }); $lastelement.css('opacity', 0); //Need to dynamically alter contents of the clone rear BEFORE it animates? Do it here //$('#cloneBack').html('hi'); //Flip the card while centering it in the screen //[hack: we have to wait for the clone to finish drawing before calling the transform so we put it in a 100 millisecond settimeout callback] setTimeout(function () { $clone.css({ 'top': '40px', 'left': '40px', 'height': '400px', 'width': $(document).width() - 140 + 'px' }); $clone.find('#cloneFront').css({ 'transform': rotatefront }); $clone.find('#cloneBack').css({ 'transform': rotateback }); }, 100); } else { $('body').click(); } }); //If user clicks outside of the flipped card, return to default state $('body').click(function (e) { if (cloneflipped) { if (e.target === e.currentTarget) { //Reverse the animation $clone.css({ 'top': lastelement.top + 'px', 'left': lastelement.left + 'px', 'height': lastelement.height + 'px', 'width': lastelement.width + 'px' }); $clone.find('#cloneFront').css({ 'transform': 'rotateY(0deg)' }); $clone.find('#cloneBack').css({ 'transform': 'rotateY(-180deg)' }); } } }); 
+19
source

Try jsFiddle

Based on this, do 3d transformation and left shift when moving,

  -webkit-transform-style:preserve-3d; -webkit-transform:rotateY(0deg); -webkit-transition:-webkit-transform 0.25s , left 0.25s; 

Use css3 conversion and transition. Hope this might work for you.)

+1
source

Maybe you like it. check my code using keyframes.

https://jsfiddle.net/jariesdev/y7Lz3mm0/

HTML:

 <div id="logo"> <a> <img src="http://fallbacks.carbonads.com/nosvn/fallbacks/2053cd7a29af8f37381467e04521a14e.png"> </a> </div> 

CSS

 #logo { -moz-transform: perspective(1000px); -moz-transform-style: preserve-3d; } #logo a { display: inline-block; } #logo:hover a { animation-name: rotateThis; animation-duration: 1s; animation-iteration-count: 1; animation-timing-function:ease-in-out; } @keyframes rotateThis { 0% { transform:scale(0) rotateY(180deg) translateX(-100%);} /*60% { transform:scale(.5) rotateY(90deg) translateX(-50%); }*/ 100% { transform:scale(1) rotateY(360deg) translateX(0);} } 
0
source

Source: https://habr.com/ru/post/971580/


All Articles