简体   繁体   English

CSS硬币翻转动画

[英]CSS Coin flip animation

So I want to create a coin flip animation, what I tried is: 所以我想创建一个硬币翻转动画,我尝试的是:

 @import "compass"; body { background-color: #edebc4; } h1 { width: 50%; margin: 0 auto; text-align: center; font-family: arial; text-transform: uppercase; } .flip-container { position: absolute; perspective: 1000; top: 50%; left: 50%; @include transform(translate(-50%, -50%)); /* flip the pane when hovered */ &:hover .flipper, &.hover .flipper { transform: rotateY(180deg); } &, .front, .back { @include border-radius(100px); width: 100px; height: 100px; overflow: hidden; } /* flip speed goes here */ .flipper { transition: 0.6s; transform-style: preserve-3d; position: relative; /* hide back of pane during swap */ .front, .back { backface-visibility: hidden; position: absolute; top: 0; left: 0; } /* front pane, placed above back */ .front { z-index: 2; /* for firefox 31 */ transform: rotateY(0deg); } /* back, initially hidden pane */ .back { transform: rotateY(180deg); } }/*.flipper*/ }/*.flip-container*/ 
 <h1>Coin flip</h1> <div class="flip-container" ontouchstart="this.classList.toggle('hover');"> <div class="flipper"> <div class="front"> <img src="//lorempicsum.com/futurama/100/100/1" alt="" /> </div> <div class="back"> <img src="//lorempicsum.com/futurama/100/100/2" alt="" /> </div> </div> </div> 

For some reason it doesn't work on my server or jsfiddle. 由于某种原因,它在我的服务器或jsfiddle上不起作用。 What's more interesting, it actually does work on codepen - http://codepen.io/mbrillaud/pen/jPdjmm 更有趣的,它实际上在codepen工作- http://codepen.io/mbrillaud/pen/jPdjmm

Example jsfiddle: https://jsfiddle.net/r0xpoqmn/ jsfiddle示例: https ://jsfiddle.net/r0xpoqmn/

What can be reason of that? 可能是什么原因呢?

The pen style is SCSS . 笔样式为SCSS Click on 'compile to CSS ' and copy the compiled code. 单击“编译为CSS ”并复制已编译的代码。 Of course, you also need to correct your image paths so switch // for http:// 当然,您还需要更正图像路径,所以将//切换为http://

SCSS is one of the syntaxes of SASS, which is a CSS preprocessor that improves the possibilities on your style code, with features like 'nesting' and 'variables'. SCSS是SASS的语法之一,它是一种CSS预处理程序,具有“嵌套”和“变量”之类的功能,可改善样式代码的可能性。

working version: link 工作版本: 链接

Your server doesn't have compass installed, if you remove compass and update the images src to use http:// instead of // you will see that it semi-works. 您的服务器没有安装指南针,如果您删除了指南针并更新了图像src以使用http://而不是//,您将看到它可以正常工作。

To fix, install compass on your server http://compass-style.org/ 要解决此问题,请在服务器上安装指南针http://compass-style.org/

The reason why your JSFiddle example does not work is because a new Fiddle defaults to CSS. 您的JSFiddle示例不起作用的原因是因为新的Fiddle默认为CSS。 Since the provided stylesheet is written using a CSS preprocessor language, you need to set the CSS panel to interpret SCSS. 由于提供的样式表是使用CSS预处理器语言编写的,因此您需要设置CSS面板以解释SCSS。

Click on the gear at the top-right of the panel and select "SCSS" as the language then paste the SCSS code from the Code Pen. 单击面板右上方的齿轮,然后选择“ SCSS”作为语言,然后从代码笔中粘贴SCSS代码。

Almost There... 快好了...

To get this to work now, you will need to do one of the following: 要使此功能立即生效,您需要执行以下操作之一:

  • Remove the @import "compass"; 删除@import "compass"; line and include the missing mixins. 行并包括缺少的mixins。 (See demo). (请参见演示)。

    or 要么

  • Fix the import and add the correct path to a CDN or local file. 修复导入,并将正确的路径添加到CDN或本地文件。


╔═══════════════╗
║ JSFiddle Demo ║
╚═══════════════╝

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM