jquery实现来回翻转效果

本文演示了如何使用jQuery创建来回翻转效果。通过检查ID的存在并动态添加,实现了元素的翻转动画。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

demo代码如下:   注意:是通过判断是否存在某种ID值,然后添加id实现的。

<!DOCTYPE html>  
<html lang="en">  
<head>  
    <meta charset="UTF-8">  
    <title>Document</title>  
    <scrip class="sr"></scrip>  
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>  
    <style type="text/css">  
        .box {  
            width: 200px;  
            height: 200px;  
            position: relative;  
        }  
        .box1,.box2 {  
            width: 200px;  
            height: 200px;  
            position: absolute;  
            top: 0;  
            left: 0;  
            text-align: center;  
            line-height: 200px;   
            font-size: 50px;  
            backface-visibility: hidden;  
            background: red;  
            transition: all 3s;  
        }  
        .box1 {  
            background: red;  
            transform: rotateY(-180deg);  
        }  
        .box2 {  
            background: blue; 
        }  
        #box2 {  
            transform: rotateY(180deg);  
        }  
        #box1 {  
            transform: rotateY(0deg);  
        }    
    </style>  
</head>  
<body>  
    <div class="box">  
        <div class="box1">CCCC</div>  
        <div class="box2">BBBB</div>  
    </div>  
    <script type="text/javascript">  
        $(".box").click(function(){  
            if($(".box1").attr("id") == undefined || $(".box1").attr("id") === ""){  
                $(".box1").attr("id","box1");  
            }else if($(".box1").attr("id") === "box1") {  
                $(".box1").attr("id","");  
            }  
            if($(".box2").attr("id") == undefined || $(".box2").attr("id") === "box1"){  
                $(".box2").attr("id","box2");  
            }else if($(".box2").attr("id") === "box2") {  
                $(".box2").attr("id","box1");  
            }  
        });  
    </script>  
</body>  
</html>  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值