从三行菜单到交叉菜单的动画转换 [英] Animated transform from three lines menu to cross
问题描述
我有一个三行动画菜单,当您单击它时会切换到一个十字.首先,您会看到三条线合为一条,然后切换为十字形.但是我想从三行跳到另一行.
I have a three-line animated menu that switches to a cross when you clicked on it. First you see the three lines go to one, and then switch to a cross. But I want skip the step from three lines to one.
我该怎么做?
这是小提琴 http://jsfiddle.net/adyocsm9/
$(document).ready(function() {
$(document).on('click', ".lines-button", function() {
$('.lines-button').addClass('close');
});
$(document).on('click', ".lines-button.close", function() {
$('.lines-button').removeClass('close');
});
});
body {
background: #000;
padding-right: 100px; /* inserted padding so stackoverflows fullscreen button does not overlay */
}
.lines-button {
position: relative;
float: right;
overflow: hidden;
margin: 0;
padding: 0;
width: 96px;
height: 56px;
font-size: 0;
text-indent: -9999px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
box-shadow: none;
border-radius: none;
border: none;
cursor: pointer;
-webkit-transition: background 0.3s;
transition: background 0.3s;
}
.lines-button:focus {
outline: none;
}
.lines-button span {
display: block;
position: absolute;
left: 18px;
right: 18px;
height: 8px;
background: white;
border-radius: 0.57143rem;
}
.lines-button span::before,
.lines-button span::after {
position: absolute;
display: block;
left: 0;
width: 100%;
height: 8px;
background-color: #fff;
border-radius: 0.57143rem;
content: "";
}
.lines-button span::before {
top: -15px;
}
.lines-button span::after {
bottom: -15px;
}
.lines {
background: none;
}
.lines span {
-webkit-transition: background 0s 0.3s;
transition: background 0s 0.3s;
}
.lines span::before,
.lines span::after {
-webkit-transition-duration: 0.3s, 0.3s;
transition-duration: 0.3s, 0.3s;
-webkit-transition-delay: 0.3s, 0s;
transition-delay: 0.3s, 0s;
}
.lines span::before {
-webkit-transition-property: top, -webkit-transform;
transition-property: top, transform;
}
.lines span::after {
-webkit-transition-property: bottom, -webkit-transform;
transition-property: bottom, transform;
}
.lines.close {
background: none;
}
.lines.close span {
background: none;
}
.lines.close span::before {
top: 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
.lines.close span::after {
bottom: 0;
-webkit-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
}
.lines.close span::before,
.lines.close span::after {
-webkit-transition-delay: 0s, 0.3s;
transition-delay: 0s, 0.3s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="lines-button lines">
<span></span>
</button>
推荐答案
您可以使用此更新的代码.我在找到它们的任何地方都删除了transition-delay
,将跨度设置为visibility: hidden;
并将伪元素设置为visibility: visible;
在切换的类中.
You can use this updated code. I removed the transition-delay
s wherever I found them, set the span to visibility: hidden;
and set the pseudo-elements to visibility: visible;
in the toggled class.
但是,由于 Internet Explorer中的错误,则该方法在该浏览器中将无法使用.展开下面的第二个片段,以查看可在IE中使用的方法.
However, due to a bug in Internet Explorer, this method won't work in that browser. Expand my second snippet below to see a method that works in IE.
$(document).ready(function () {
$(document).on('click', ".lines-button", function () {
$('#overlay').show();
$('.lines-button').addClass('close');
});
$(document).on('click', ".lines-button.close", function () {
$('#overlay').hide();
$('.lines-button').removeClass('close');
});
});
body {
background: #000;
}
.lines-button {
position: relative;
float:right;
overflow: hidden;
margin: 0;
padding: 0;
width: 96px;
height: 56px;
font-size: 0;
text-indent: -9999px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
box-shadow: none;
border-radius: none;
border: none;
cursor: pointer;
-webkit-transition: background 0.3s;
transition: background 0.3s;
}
.lines-button:focus {
outline: none;
}
.lines-button span {
display: block;
position: absolute;
left: 18px;
right: 18px;
height: 8px;
background: white;
border-radius: 0.57143rem;
}
.lines-button span::before, .lines-button span::after {
position: absolute;
display: block;
left: 0;
width: 100%;
height: 8px;
background-color: #fff;
border-radius: 0.57143rem;
content:"";
}
.lines-button span::before {
top: -15px;
}
.lines-button span::after {
bottom: -15px;
}
.lines {
background: none;
}
.lines span {
-webkit-transition: background 0s 0.3s;
transition: background 0s 0.3s;
}
.lines span::before, .lines span::after {
-webkit-transition-duration: 0.3s, 0.3s;
transition-duration: 0.3s, 0.3s;
}
.lines span::before {
-webkit-transition-property: top, -webkit-transform;
transition-property: top, transform;
}
.lines span::after {
-webkit-transition-property: bottom, -webkit-transform;
transition-property: bottom, transform;
}
.lines.close {
background: none;
}
.lines.close span {
visibility: hidden;
}
.lines.close span::before {
top: 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
visibility: visible;
}
.lines.close span::after {
bottom: 0;
-webkit-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
visibility: visible;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="lines-button lines"><span></span></button>
此版本仅使用CSS;复选框方法.它也可以在所有现代浏览器和IE9 +中使用.
This version uses CSS only; the checkbox method. It also works in all modern browsers and IE9+.
body {
background: #000;
margin: 0;
}
#hamburger {
position: fixed;
left: -9999px;
}
.line {
display: block;
height: 8px;
width: 60px;
background: white;
border-radius: 0.57143rem;
cursor: pointer;
position: absolute;
top: 35px;
right: 24px;
}
.top, .bottom {
display: block;
position: absolute;
height: 8px;
background: white;
border-radius: 0.57143rem;
top: 20px;
}
.bottom {
top: 50px;
}
.line {
-webkit-transition: background 0s 0s;
transition: background 0s 0s;
}
.top, .bottom {
-webkit-transition-duration: 0.3s, 0.3s;
transition-duration: 0.3s, 0.3s;
-webkit-transition-property: top, -webkit-transform;
transition-property: top, transform;
}
.middle {
-webkit-transition-property: opacity, -webkit-transform;
transition-property: opacity, transform;
}
#hamburger:checked ~ .middle {
opacity: 0;
}
#hamburger:checked + .top {
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
top: 35px;
}
#hamburger:checked ~ .bottom {
-webkit-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
top: 35px;
}
<input type="checkbox" id="hamburger" />
<label for="hamburger" class="top line"></label>
<label for="hamburger" class="middle line"></label>
<label for="hamburger" class="bottom line"></label>
这篇关于从三行菜单到交叉菜单的动画转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!