跳动的心(适合表白)

今天用javascript,css,html做了一个动态效果

一.先画一个爱心

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
.f{
    width: 200px;
    height: 180px;
    position: relative;
    left:200px;
    top:200px;
}
    .f>div{
            position: absolute;
        }
        .z1,.z2{
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background-color: red;
        }
        .z2{
            left:70px;
 }
 .z3{
            width: 100px;
            height: 100px;
            background-color: red;
            left: 35px;
            top: 35px;
            transform: rotate(45deg);
            
        }
</style>
<body>
    <div id="divF"class="f">
        <div class="z1"></div>
        <div class="z2"></div>
        <div class="z3"></div>
        </div>
</body>
</html>

结果图: 

 

二.制作爱心动态效果:

apocity属性是指定一个元素的透明度。

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
   
        @keyframes jump {
            from{
                transform: scale(0.5);
                opacity: 0.5;
            }to{
                transform: scale(2);
                opacity: 1;
                
            }
        }
        .f{
            width: 200px;
            height: 180px;
            position: relative;
            left:200px;
            top:200px;
           
        }
        .m{animation: jump 0.7s ease alternate infinite;}
        .f>div{
            position: absolute;
        }
        .z1,.z2{
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background-color: red;
        }
        .z2{
            left:70px;
        }
        .z3{
            width: 100px;
            height: 100px;
            background-color: red;
            left: 35px;
            top: 35px;
            transform: rotate(45deg);
            
        }
        button{
            width:80px;
            height: 40px;
            background-color: skyblue;
            border: none;
            color: white;
            font-size: large;
            border-radius: 10px;
            cursor: pointer;
            box-shadow: 0 8px 5px gray;
            margin-left: 20px;
        }
        button:active{
            transform: translate(5px,5px);
        }
</style>
<body>
    <button onclick="start1()">开始</button>
    <button onclick="stop1()">结束</button>
    <div id="divF"class="f">
        <div class="z1"></div>
        <div class="z2"></div>
        <div class="z3"></div>
        </div>
</body>
<script>
    let divF=document.getElementById('divF')
    function start1(){
            divF.className='f m'
    }
    function stop1(){
            divF.className='f'
    }
</script>
</html>

效果图: 

 

 

三.再加一些语言旋转效果: 

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>心动的感觉</title>
    <style>
        @keyframes jump {
            from{
                transform: scale(0.5);
                opacity: 0.5;
            }to{
                transform: scale(2);
                opacity: 1;
                
            }
        }
        @keyframes circles{
            from{
                transform: rotate(0deg);
                z-index: 1;
            }to{
                transform: rotate(360deg);
                z-index: -1;
            }
        }
        .f{
            width: 200px;
            height: 180px;
            position: relative;
            left:200px;
            top:200px;
            /*animation: jump 0.7s ease alternate infinite;*/
        }
        .m{animation: jump 0.7s ease alternate infinite;}
        .f>div{
            position: absolute;
        }
        .z1,.z2{
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background-color: red;
        }
        .z2{
            left:70px;
        }
        .z3{
            width: 100px;
            height: 100px;
            background-color: red;
            left: 35px;
            top: 35px;
            transform: rotate(45deg);
            
        }
        .z4{
            top:50px;
            left: 45px;
            font-size:large;
            color: white;
            z-index: -1;
        }
        .z4c{animation: circles 1s linear 2s infinite ;

        }
        button{
            width:80px;
            height: 40px;
            background-color: skyblue;
            border: none;
            color: white;
            font-size: large;
            border-radius: 10px;
            cursor: pointer;
            box-shadow: 0 8px 5px gray;
            margin-left: 20px;
        }
        button:active{
            transform: translate(5px,5px);
        }
    </style>
</head>
<body>
    <button onclick="start1()">开始</button>
    <button onclick="stop1()">结束</button>
    <div id="divF"class="f">
        <div class="z1"></div>
        <div class="z2"></div>
        <div class="z3"></div>
        <div id="z4"class="z4">I &emsp;O &emsp; U</div>
    </div>
    </body>
    <script>
        let divF=document.getElementById('divF')
        let z4=document.getElementById('z4')
        function start1(){
            divF.className='f m'
            z4.className='z4 z4c'
        }
        function stop1(){
            divF.className='f'
            z4.className='z4'
        }
    </script>

</html>

效果

 

这就是我写的代码供大家参考,希望大家喜欢! 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 这是一段C语言编写的表白代码: ``` #include <stdio.h> #include <unistd.h> int main() { int i; for (i = 0; i < 10; i++) { printf("I ❤️ You\n"); sleep(1); printf("\033[A"); // 擦除上一行 printf("\033[A"); // 擦除上一行 } return 0; } ``` 这段代码在终端中运行,每隔一秒钟,会打印一个“I ❤️ You”的爱,然后使用ANSI控制码擦除上一行内容,让爱不断跳动。 ### 回答2: #include <stdio.h> #include <time.h> #include <windows.h> // 定义跳动表白符号 // 使用了转义字符\033来实现符号颜色的控制 #define HEART "\033[1;31m♥\033[0m" // 延迟函数,用于控制符号的跳动速度 void delay(unsigned int milliseconds) { clock_t start_time = clock(); while (clock() < start_time + milliseconds) ; } int main() { // 控制台窗口大小 system("mode con cols=80 lines=40"); int i, j; int width, height, top, bottom, left, right; // 获取窗口尺寸信息 HWND hWnd = GetForegroundWindow(); RECT rc; GetWindowRect(hWnd, &rc); width = rc.right - rc.left; height = rc.bottom - rc.top; top = rc.top; left = rc.left; bottom = top + 40; right = left + 80; // 设置窗口位置居中 SetWindowPos(hWnd, 0, (GetSystemMetrics(SM_CXSCREEN) - width) / 2, (GetSystemMetrics(SM_CYSCREEN) - height) / 2, 0, 0, SWP_NOSIZE | SWP_NOZORDER); // 清空窗口 system("cls"); while (1) { for (i = top; i <= bottom; i++) { // 移动控制台光标到指定位置 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), (COORD){left, i}); // 输出跳动表白形 for (j = left; j <= right; j++) { if ((j >= left + 2 && j <= right - 2 && (i == top || i == bottom)) || (i >= top + 3 && i <= bottom - 2 && (j == left + 1 || j == right - 1)) || (j == left + 2 && i == top + 2)) { printf(HEART); } else { printf(" "); } } } delay(200); // 延迟200毫秒 // 清空窗口 system("cls"); } return 0; } ### 回答3: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #define SIZE 9 int main() { char heart[SIZE][SIZE] = { {' ', ' ', ' ', '*', ' ', ' ', ' ', '*', ' '}, {' ', ' ', '*', ' ', '*', ' ', '*', ' ', '*'}, {' ', '*', ' ', ' ', ' ', '*', ' ', ' ', ' '}, {'*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, {' ', '*', ' ', ' ', ' ', '*', ' ', ' ', ' '}, {' ', ' ', '*', ' ', '*', ' ', '*', ' ', '*'}, {' ', ' ', ' ', '*', ' ', ' ', ' ', '*', ' '}, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '} }; int i, j, flag = 0; while (1) { system("clear"); // 清屏 for (i = 0; i < SIZE; i++) { for (j = 0; j < SIZE; j++) printf("%c", heart[i][j]); printf("\n"); } if (flag == 0) { heart[SIZE - 1][SIZE / 2] = ' '; flag = 1; } else { heart[SIZE - 1][SIZE / 2] = '*'; flag = 0; } usleep(300000); // 300毫秒 } return 0; } 代码通过使用二维字符数组来表示一个形,然后通过循环不断地显示和隐藏形的下半部分以达到跳动的效果。首先,在main函数中定义了一个9x9的字符数组heart,用来表示形的形状。接着使用一个循环,不断地清屏并打印出数组heart中的内容,以达到跳动效果。在每次打印之前,根据flag的值来修改数组heart的最后一行,从而显示或隐藏形的下半部分。最后,使用usleep函数让程序延迟300毫秒,控制形的跳动速度。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值