CSS3让登陆面板3D旋转起来
程序员文章站
2023-11-10 14:04:46
点击登陆面板会发生360度旋转,并显示信息,真正使用CSS3让登陆面板3D旋转起来,如何实现登陆面板3D旋转,感兴趣的小伙伴们可以参考一下... 16-05-03...
本文实例为大家分享了利用css3实现登陆面板3d旋转起来的具体代码,供大家参考,具体内容如下
效果图:
点击登陆,登陆面板会发生360度旋转,并显示信息。
旋转结束:
示例代码:
xml/html code复制内容到剪贴板
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>登陆面板旋转</title>
- <style>
- body {
- font-family: "microsoft yahei", "微软雅黑";
- }
- .container {
- /*创建3d场景*/
- -webkit-perspective: 800;
- -webkit-perspective-origin: 50% 50%;
- -webkit-transform-style: -webkit-preserve-3d; /*告诉浏览器以下transform操作是在3d场景下进行的*/
- }
- #login-panel {
- /*-webkit-transform: rotatex(45deg);*/
- }
- .login {
- width: 500px;
- height: 400px;
- margin: 100px auto;
- text-align: center;
- border: 1px solid #abcdef;
- border-radius: 10px;
- box-shadow: 0 0 3px 3px #abcdef;
- }
- .login h1 {
- margin: 50px 0;
- }
- .login-row span {
- font-size: 18px;
- }
- .login-row input {
- height: 25px;
- line-height: 25px;
- padding: 0 10px;
- margin: 10px 0;
- }
- .btn {
- outline: none;
- background-color: aliceblue;
- cursor: pointer;
- width: 90px;
- height: 40px;
- border: 1px solid #ddd;
- border-radius: 5px;
- margin: 30px 20px;
- font-size: 16px;
- transition: background-color 0.5s;
- -webkit-transition: background-color 0.5s;
- -moz-transition: background-color 0.5s;
- -o-transition: background-color 0.5s;
- }
- .btn:hover {
- background-color: antiquewhite;
- }
- .login-success {
- font-size: 20px;
- padding: 50px;
- }
- </style>
- <script>
- var loginbtn, regibtn;
- window.onload = function() {
- loginbtn = document.getelementbyid("login");
- loginbtn.onclick = rotate;
- regibtn = document.getelementbyid("regi");
- regibtn.onclick = rotate;
- };
- function rotate() {
- var x = 0;
- var panel = document.getelementbyid("login-panel");
- panel.style.transform = "rotatex(0deg)";
- panel.style.webkittransform = "rotatex(0deg)";
- var flag = true;
- var timer = setinterval(function() {
- if(math.round(x) >= 90 && flag) {
- panel.innerhtml = "<p class='login-success'>登陆成功</p>";
- flag = false;
- }
- if(math.round(x) >= 358) {
- panel.style.transform = "rotatex(360deg)";
- panel.style.webkittransform = "rotatex(360deg)";
- clearinterval(timer);
- return false;
- } else {
- x += 2 + (360 - x) / 60;
- panel.style.transform = "rotatex(" + x + "deg)";
- panel.style.webkittransform = "rotatex(" + x + "deg)";
- }
- }, 25);
- }
- </script>
- </head>
- <body>
- <div class="container">
- <div class="login" id="login-panel">
- <h1>登陆</h1>
- <div class="login-row">
- <label for="username"><span>账号:</span></label>
- <input type="text" id="username" name="username">
- </div>
- <div class="login-row">
- <label for="password"><span>密码:</span></label>
- <input type="password" id="password" name="password">
- </div>
- <div class="login-row">
- <button id="login" class="btn" type="button">登陆</button>
- <button id="regi" class="btn" type="button">注册</button>
- </div>
- </div>
- </div>
- </body>
- </html>
以上就是本文的全部内容,希望对大家的学习有所帮助。