简体   繁体   English

JavaScript硬币翻转动画,两侧带有自定义图像

[英]JavaScript coin flip animation with custom image on either side

I'm currently developing a site in which 2 users go head to head in a "coin flip", a Materialize CSS modal pops up on each users screen (the winner has already been defined), I then want there to be a coin flip animation. 我目前正在开发一个网站,其中有2个用户在“硬币翻转”中并肩作战,每个用户屏幕上都会弹出一个Materialize CSS模式(已经确定了获胜者),然后我希望有一个硬币翻转动画。

I'm going to use this coin flip animation: https://www.html5andbeyond.com/coin-flip-application-html-css-and-jquery/ 我将使用此硬币翻转动画: https : //www.html5andbeyond.com/coin-flip-application-html-css-and-jquery/

My question is how can I set the coin flip to land on a specific winner before the animation, also, how can I change it so there's a custom image on each side? 我的问题是,如何在动画制作之前将硬币翻转设置为落在特定的获胜者身上,并且如何更改它,以便在每侧都有自定义图像?

Thanks, 谢谢,

James 詹姆士

Here are the changes to make in the css of that Codepen to place an image on either side of the coin. 这是在Codepen的CSS中进行的更改,以将图像放置在硬币的两侧。 Click 'Edit on Codepen' on https://codepen.io/html5andblog/pen/pJZpee 点击https://codepen.io/html5andblog/pen/pJZpee上的“在Codepen上编辑”

#coin .front {
    transform: translateZ(1px);
    border-radius: 50%;
    background-image: url('http://placehold.it/200x200/E8117F/000000');
    background-size: cover;
    display: block;
}

    #coin .back {
    transform: translateZ(-1px) rotateY(180deg);
    border-radius: 50%;
    background-image: url('http://placehold.it/200x200/000000/E8117F');
     background-size: cover;
     display: block;
}

To make the coin fall on a specific side do the following on that same codepen you gave us. 为了使硬币落在特定的一面,请在您给我们的同一密码笔上执行以下操作。

Heads: Change the 'var spinArray' line to 头:将“ var spinArray”行更改为

var spinArray = ['animation1080'];

Tails: Change the 'var spinArray' line to 尾巴:将“ var spinArray”行更改为

var spinArray = ['animation900'];

I can't take it any further without having access to your code. 如果无法访问您的代码,我将无法再进行进一步的开发。 That should be enough to figure it out though. 那应该足以弄清楚它。

Hope this helps. 希望这可以帮助。

Best, 最好,

Tim 提姆

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

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