css 跳動的心_如何用純CSS為您的情人打造一顆跳動的心

css 跳動的心

Each year on February 14th, many people exchange cards, candies, gifts or flowers with their special “valentine”. The day of romance we call Valentine’s Day is named for a Christian martyr and dates back to the 5th century, but has origins in the Roman holiday Lupercalia.

每年2月14日,許多人都用他們特殊的“情人節”來交換卡片,糖果,禮物或鮮花。 我們稱之為情人節的浪漫之日以基督教烈士而命名,其歷史可以追溯到5世紀,但起源于羅馬假日盧佩卡利阿(Lupercalia)。

Ok so far so good. But what can a programmer do for their Valentine?

好的,到目前為止很好。 但是程序員可以為他們的情人做什么?

My answer is: use CSS and be creative!

我的答案是:使用CSS并發揮創造力!

I really love CSS. It’s not a really sophisticated language (it’s not even considered a programming language most of the time). But with some geometry, mathematics and some basic CSS rules, you can turn your browser into a canvas of your creativity!

我真的很喜歡CSS。 它不是一種真正復雜的語言(大多數時候甚至都不被視為編程語言)。 但是,有了一些幾何,數學和一些基本CSS規則,您就可以將瀏覽器變成具有創造力的畫布!

So let’s start. How would you create a heart with pure Geometry?

因此,讓我們開始吧。 您將如何創建具有純幾何形狀的心臟?

You just need a square and two circles. Right?

您只需要一個正方形和兩個圓圈。 對?

And we can draw that with a single element, thanks to the ::after and ::before pseudo elements. Speaking about pseudo elements, ::after is a pseudo element which allows you to insert content into a page from CSS (without it needing to be in the HTML). ::before is exactly the same, only it inserts the content before any other content in the HTML instead of after.

而且,由于::after::before偽元素,我們可以使用單個元素進行繪制。 說到偽元素, ::after是一個偽元素,它允許您將內容從CSS插入頁面(無需在HTML中插入)。 ::before完全相同,只是它在HTML中的其他任何content之前而不是after之后插入content

For both pseudo elements, the end result is not actually in the DOM, but it appears on the page as if it would be.

對于這兩個偽元素,最終結果實際上不在DOM中,但它看起來像在頁面中一樣。

So let’s create our heart.

因此,讓我們創建自己的心。

.heart {background-color: red;display: inline-block;height: 50px;margin: 0 10px;position: relative;top: 0;transform: rotate(-45deg);position: absolute; left: 45%; top: 45%;width: 50px;
}.heart:before,
.heart:after {content: "";background-color: red;border-radius: 50%;height: 50px;position: absolute;width: 50px;
}.heart:before {top: -25px;left: 0;
}.heart:after {left: 25px;top: 0;
}

You can easily notice that we define the square and its positioning by using the main ‘heart’ class and the two circles with the ::before and ::after pseudo elements. The circles are actually just 2 more squares that have their border-radius reduced to the half.

您可以輕松地注意到,通過使用主要的“心臟”類以及帶有::before::after偽元素的兩個圓,我們定義了正方形及其位置。 圓圈實際上只是另外2個正方形,其邊界半徑減小了一半。

But what is a heart without beating?

但是沒有跳動的心是什么?

Let’s create a pulse. Here we are going to use the @keyframes rule. The @keyframes CSS at-rule is used to define the behaviour of one cycle of a CSS animation.

讓我們創建一個脈沖。 在這里,我們將使用@keyframes規則。 @keyframes CSS規則用于定義CSS動畫一個周期的行為。

When we are using the keyframes rule, we can divide a time period to smaller parts and create a transformation/animation by splitting it into steps (each step corresponds to a percentage of the completion of the time period).

當使用關鍵幀規則時,我們可以將時間段劃分為較小的部分,并通過將其分成多個步驟來創建轉換/動畫(每個步驟對應于該時間段完成的百分比)。

So let’s create the heartbeat. Our heartbeat animation consists of 3 steps:

因此,讓我們創建心跳。 我們的心跳動畫包括3個步驟:

@keyframes heartbeat {0% {transform: scale( 1 );    }20% {transform: scale( 1.25 ) translateX(5%) translateY(5%);} 40% {transform: scale( 1.5 ) translateX(9%) translateY(10%);}
}
  1. On 0% of the time period we start with no transformation.

    在0%的時間段內,我們不進行任何轉換。
  2. On 20% of the time period we scale our shape to 125% of its initial size.

    在20%的時間段內,我們將形狀縮放到其初始大小的125%。
  3. On 40% of the time period we scale our shape to 150% of its initial size.

    在40%的時間段內,我們將形狀縮放到其初始大小的150%。

For the remaining 60% of the time period we leave time for our heart to return to its initial state.

在剩下的60%的時間里,我們有時間讓心臟恢復到初始狀態。

Finally we have to assign the animation to our heart.

最后,我們必須將動畫分配給我們。

.heart {animation: heartbeat 1s infinite; // our heart has infinite heartbeat :)...
}

That’s it!

而已!

We have a beating heart that will beat forever.Or maybe as long as your own love lasts…

我們有一顆跳動的心,它將永遠跳動。或者也許只要你自己的愛持續下去……

Feel free to check out the related Codepen:

隨時查看相關的Codepen:

I wish you a wonderful Valentine’s day!

祝您情人節快樂!

翻譯自: https://www.freecodecamp.org/news/how-to-create-a-beating-heart-with-pure-css-for-your-valentine-2aeb05e2d36e/

css 跳動的心

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/392218.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392218.shtml
英文地址,請注明出處:http://en.pswp.cn/news/392218.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

oracle怎么獲取行,在oracle中如何實現SELECT TOP N取得前幾行記錄

在sql server中可以通過SELECT TOP N來取得想要結果的前幾行的信息。但是在oracle中必須借助偽列rownum來完成一個查詢語句在取得結果集后,偽列rownum就會從1開始,從上往下依次遞增。rownum是對結果集的編序排列。例如下表:SQL> select id…

圖片管理程序(Java)

圖片管理程序 gitee完整代碼下載 github完整代碼下載 華南農業大學課程設計作品(99分) 問題描述 題目目的是編寫一個能夠對數字像片進行管理的應用程序。 程序能夠顯示的圖片格式包括,.JPG、.JPEG、.GIF、.PNG、和.BMP。 圖像文件尺寸,要求能夠處理從…

氣流與路易吉,阿戈,MLFlow,KubeFlow

任務編排工具和工作流程 (Task orchestration tools and workflows) Recently there’s been an explosion of new tools for orchestrating task- and data workflows (sometimes referred to as “MLOps”). The quantity of these tools can make it hard to choose which o…

移動WEB開發之JS內置touch事件[轉]

iOS上的Safari也支持click 和mouseover等傳統的交互事件,只是不推薦在iOS的瀏覽器應用上使用click和mouseover,因為這兩個事件是為了支持鼠標點擊而設計 出來的。Click事件在iOS上會有半秒左右的延遲,原因是iOS要highlight接收到click的eleme…

編寫代碼的軟件用什么編寫的_如何通過像編寫代碼一樣克服對編寫的恐懼

編寫代碼的軟件用什么編寫的by Chris Rowe通過克里斯羅 How often do you get the fear? What do I mean by fear? How about the knot I got in my stomach just before I plunged out of plane on a parachute jump? It’s more than the brain logically planning to av…

快速學習一個新的模塊

1、模塊名.__doc__查看函數簡介,為了便于查看,采用print(模塊名.__doc__)打印出來,這樣的格式便于查看。 2、采用內置方法dir()查看模塊的變量、函數、類等等;采用"模塊名.__all__"查看模塊中提供…

php 公鑰格式轉換,如何把OpenSSH公鑰轉換成OpenSSL格式

《如何把OpenSSH公鑰轉換成OpenSSL格式》要點:本文介紹了如何把OpenSSH公鑰轉換成OpenSSL格式,希望對您有用。如果有疑問,可以聯系我們。首先看看OpenSSL工具的簡單使用方法,我們以rsa加密算法為例生成一個私鑰:openssl genrsa -o…

模擬操作系統(Java)

gitee完整代碼下載 github完整代碼下載 一、 需求分析 模擬一個采用多道程序設計方法的單用戶操作系統,該操作系統包括進程管理、存儲管理、設備管理、文件管理和用戶接口四部分。預計程序所能達到的功能: 進程管理模擬:實現操作系統進程管…

數據庫面試復習_數據科學面試復習

數據庫面試復習大面試前先刷新 (REFRESH BEFORE THE BIG INTERVIEW) 介紹 (Introduction) I crafted this study guide from multiple sources to make it as comprehensive as possible. This guide helped me prepare for both the technical and behavioral aspects of the …

hibernate緩存

(轉自:http://www.cnblogs.com/java-class/p/6108175.html) 閱讀目錄 1. 為什么要用 Hibernate 緩存?2. 項目實戰3. Hibernate 緩存原理回到頂部1. 為什么要用 Hibernate 緩存? Hibernate是一個持久層框架,…

oracle 連接greenplum,Oracle通過DBLINK訪問GreenPlum

為多個數據庫之間的整合和遷移做POC,嘗試使用Oracle Gateway和Heterogeneous Service來中轉訪問,測試過好多次,最終發現只有在32位的Oracle當中才能成功配置。 配置環境如下: Windows 2003 32bit 或 Windows 2008 64bit Oracle10G…

如何使用React和Redux前端創建Rails項目

by Mark Hopson馬克霍普森(Mark Hopson) 如何使用React和Redux前端(加上Typescript!)創建Rails項目 (How to create a Rails project with a React and Redux front-end (plus Typescript!)) 在Rails項目中使用React和Redux設置單頁Javascript App的完整指南。 (A …

分布與并行計算—用任務管理器畫CPU正弦曲線(Java)

class drawSin implements Runnable{Overridepublic void run() {final double SPLIT 0.01;// 角度的分割final int COUNT (int) (2 / SPLIT);// 2PI分割的次數,也就是2/0.01個,正好是一周final double PI Math.PI;final int interval 100;// 時間間…

Rails文件上傳file_field報錯Encoding::UndefinedConversionError

服務器用的是ubuntu12 64bit,環境是ruby1.9.3rails3mysql,測試是在windows2003上。 上傳一個【.gitconfig】文件,沒有問題,上傳【新浪微博數據挖掘.pdf】報錯,上傳【back.jpg】報錯。 下面是兩段信息,是從【…

好久不來這里寫東西了.

我正準備離開學校去實現自己的目標,很清楚自己在學校的... ...做共享程序員,就不得不考慮些商業上的東西,自己要吃飯啊!我想我是該好好的處理一下這二者的關系. 轉載于:https://www.cnblogs.com/wangxiang/archive/2007/01/01/609714.html

Asp.net mvc中使用配置Unity

第一步:添加unity.mvc 第二步:在添加之后會在app_start中生成UnityConfig.cs,UnityMvcActivator.cs 第三步:使用 第四步:效果展示 轉載于:https://www.cnblogs.com/WJ--NET/p/7117839.html

頂級數據恢復_頂級R數據科學圖書館

頂級數據恢復Data science is the discipline of making data useful數據科學是使數據有用的學科 When we talk about the top programming language for Data Science, we often find Python to be the best fit for the topic. Sure, Python is undoubtedly an excellent cho…

xp系統oracle數據庫,Oracle10g 數據庫的安裝基于windowsXP

Oracle的安裝一、首先去官網下載自身系統相對應的數據庫軟件http://www.oracle.com/cn/index.htmlOracle軟件本身是免費的,個人用途完全沒關系,商業用途并被發現才會被Oracle所要求收費,收費買的不是軟件,而是授權。何謂授權&…

了解React Native中的不同JavaScript環境

by Khoa Pham通過Khoa Pham 了解React Native中的不同JavaScript環境 (Get to know different JavaScript environments in React Native) React Native can be very easy to get started with, and then at some point problems occur and we need to dive deep into it.Reac…

分布與并行計算—生命游戲(Java)

生命游戲其實是一個零玩家游戲,它包括一個二維矩形世界,這個世界中的每個方格居住著一個活著的或死了的細胞。一個細胞在下一個時刻生死取決于相鄰八個方格中活著的或死了的細胞的數量。如果相鄰方格活著的細胞數量過多,這個細胞會因為資源匱…