ChatGPT手把手教你实现轮播图

实现轮播图的小Demo

Demo的目录结构
在这里插入图片描述

备注:我这使用的是ChatGPT3.5,不是最新的ChatGPT4

ChatGPT使用CSS实现轮播图

  • 效果展示
    在这里插入图片描述
  • ChatGPT写的代码
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            #container {
                /* width: w */
                width: 400px;
                /* height: h */
                height: 300px;
                overflow: hidden;
            }
            
            #photo {
                /* width: 3w */
                width: 1200px;
                animation: switch 5s ease-out infinite;
            }
            
            #photo>img {
                float: left;
                /* width: w */
                width: 400px;
                /* height: h */
                height: 300px;
            }
            
            @keyframes switch {
                0%,
                25% {
                    margin-left: 0;
                }
                35%,
                60% {
                    /* w */
                    margin-left: -400px;
                }
                70%,
                100% {
                    /* 2w */
                    margin-left: -800px;
                }
            }
        </style>
    </head>
    
    <body>
        <div id="container">
            <div id="photo">
                <img src="./img/1.jpg" />
                <img src="./img/2.jpg" />
                <img src="./img/3.jpg" />
            </div>
        </div>
    </body>
    
    </html>
    

ChatGPT使用JavaScript实现轮播图

  • 效果展示
    在这里插入图片描述
  • ChatGPT写的代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ChartGPT编写的轮播图</title>
    <!-- 
        备注:这是ChartGPT实现的,我对其稍微改动了一下
        https://chat.openai.com/chat
     -->


    <style>
        #slider {
            position: relative;
            width: 500px;
            height: 300px;
            overflow: hidden;
        }
        
        #slider img {
            position: absolute;
            width: 100%;
            height: 100%;
        }
        
        #slider img:not(:nth-child(1)) {
            opacity: 0;
            transition: opacity 1s;
        }
        
        #slider img.active {
            opacity: 1;
        }
    </style>
</head>

<body>
    <div id="slider">
        <img src="./img/1.jpg" alt="Image 1">
        <img src="./img/2.jpg" alt="Image 2">
        <img src="./img/3.jpg" alt="Image 3">
    </div>
    <script>
        var slider = document.getElementById("slider");
        var images = slider.getElementsByTagName("img");
        var current = 0;

        function nextImage() {
            images[current].classList.remove("active");
            current = (current + 1) % images.length;
            images[current].classList.add("active");
        }

        setInterval(nextImage, 3000);
    </script>
</body>

</html>

结语

总的来讲,ChatGPT是能够实现轮播图效果的,但是如果想要更加丝滑或者说更符合你的需求,需要手动修改一下。不得不说ChatGPT真的是越用越爽,强烈建议大家去尝试接触一下这个新东西。至于如何使用,这就需要进行”科学上网“了,至于如何”科学上网“,这里就不再详细介绍了,相信大家只要有好奇心,到网上搜一下就能知道 O(∩_∩)O
最后送大家一句话:ChatGPT这个工具本身是不能够直接取代人的,但是能够善用这个工具的人,是能够取代更多的人

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

知识汲取者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值