一键缩放和翻转功能,鼠标经过翻转和缩放功能
Posted shoucong li
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一键缩放和翻转功能,鼠标经过翻转和缩放功能相关的知识,希望对你有一定的参考价值。
<!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>
<script src="jquery-3.6.0.js"></script>
<style>
*{box-sizing: border-box;}
html,body{margin:0;padding:0;height:100%}
ul,ol{margin:0;padding:0;list-style: none;}
.wrapper{
width:800px;
margin:0 auto
}
ul.words{display: flex;flex-wrap: wrap;}
ul.words li{width:25%;border:1px solid #f00;height:100px;position: relative;color:#fff}
.cn{position: absolute;width:100%;height:100%;background-color: rgba(0,0,0,1);transition:2s;}
.en{position: absolute;width:100%;height:100%;background-color: rgba(50,0,0,1);transition:2s;}
ul li{transition: 1s;transform:rotateY(0deg);}
.cn,.en{transform: perspective(200px);}
.hide{transform:rotateY(-180deg);opacity: 0;}
</style>
</head>
<body>
<div class="btns">
<button id="btncn">转成中文</button>
<button id="btnen">转成英文</button>
</div>
<div class="wrapper">
<ul class="words">
<li>
<div class="cn">中国</div>
<div class="en hide">chinaz</div>
</li>
<li>
<div class="cn">英国</div>
<div class="en hide">english</div>
</li>
<li>
<div class="cn">中国</div>
<div class="en hide">chinaz</div>
</li>
<li>
<div class="cn">英国</div>
<div class="en hide">english</div>
</li>
<li>
<div class="cn">中国</div>
<div class="en hide">chinaz</div>
</li>
<li>
<div class="cn">英国</div>
<div class="en hide">english</div>
</li>
<li>
<div class="cn">中国</div>
<div class="en hide">chinaz</div>
</li>
<li>
<div class="cn">英国</div>
<div class="en hide">english</div>
</li>
</ul>
</div>
</body>
<script>
$("#btncn").on("click",function(){
$(".cn").toggleClass("hide").next().toggleClass("hide")
})
$("ul li")
.on("mouseenter",function(){
$(this).find(".cn").toggleClass("hide").next().toggleClass("hide")
})
.on("mouseleave",function(){
$(this).find(".cn").toggleClass("hide").next().toggleClass("hide")
})
</script>
</html>
翻转见上
<!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>
<script src="jquery-3.6.0.js"></script>
<style>
*{box-sizing: border-box;}
html,body{margin:0;padding:0;height:100%}
ul,ol{margin:0;padding:0;list-style: none;}
.wrapper{
width:800px;
margin:0 auto
}
ul.words{display: flex;flex-wrap: wrap;}
ul.words li{width:25%;border:1px solid #f00;height:100px;position: relative;color:#fff}
.cn{position: absolute;width:100%;height:100%;background-color: rgba(0,0,0,1);transition:0.3s;backface-visibility: hidden;}
.en{position: absolute;width:100%;height:100%;background-color: rgba(50,0,0,1);transition:0.3s;backface-visibility: hidden;}
/* ul li{transition: 1s;transform:rotateY(0deg);} */
.hide{transform: scale(0);}
</style>
</head>
<body>
<div class="btns">
<button id="btncn">转成中文</button>
<button id="btnen">转成英文</button>
</div>
<div class="wrapper">
<ul class="words">
<li>
<div class="cn">中国</div>
<div class="en hide">chinaz</div>
</li>
<li>
<div class="cn">英国</div>
<div class="en hide">english</div>
</li>
<li>
<div class="cn">中国</div>
<div class="en hide">chinaz</div>
</li>
<li>
<div class="cn">英国</div>
<div class="en hide">english</div>
</li>
<li>
<div class="cn">中国</div>
<div class="en hide">chinaz</div>
</li>
<li>
<div class="cn">英国</div>
<div class="en hide">english</div>
</li>
<li>
<div class="cn">中国</div>
<div class="en hide">chinaz</div>
</li>
<li>
<div class="cn">英国</div>
<div class="en hide">english</div>
</li>
</ul>
</div>
</body>
<script>
$("#btncn").on("click",function(){
$(".cn").toggleClass("hide").next().toggleClass("hide")
})
$("ul li")
.on("mouseenter",function(){
$(this).find(".cn").toggleClass("hide").next().toggleClass("hide")
})
.on("mouseleave",function(){
$(this).find(".cn").toggleClass("hide").next().toggleClass("hide")
})
</script>
</html>
缩放
以上是关于一键缩放和翻转功能,鼠标经过翻转和缩放功能的主要内容,如果未能解决你的问题,请参考以下文章