当我单击ul的汉堡包时,是否可以水平移动徽标并将徽标从中心移到最左端?

时间:2019-02-08 13:56:59

标签: javascript jquery html css animation

我可以单击汉堡菜单并同时水平和垂直打开它吗?您可以在图像上看到我真正想要的东西,当我单击汉堡包时,基本上我想要一个动画,因此徽标移到最左边,并且它们都必须以相同的速度移动。而且社交媒体必须垂直。

点击前。 before clicking

after clicking

点击后。

    @import url('https://fonts.googleapis.com/css?family=Varela+Round');
html, body {
    overflow-x: hidden;
    height: 100%;
}
body {
    background-image: url('https://www.3ctele.com/wp-content/uploads/2015/12/3c-gradient-background.png');
    background-size: cover;
    height: 100vh;
    padding: 0;
    margin: 0;
    font-family: 'Varela Round', sans-serif;
}
.header {
    display: block;
    margin: 0 auto;
    width: 100%;
    max-width: 100%;
    box-shadow: none;
    background-color: transparent;
    position: fixed;
    height: 60px!important;
    overflow: hidden;
    z-index: 10;
}
.main {
    margin: 0 auto;
    display: block;
    height: 100%;
    margin-top: 60px;
}
.mainInner{
    display: table;
    height: 100%;
    width: 100%;
    text-align: center;
}
.mainInner div{
    display:table-cell;
    vertical-align: middle;
    font-size: 3em;
    font-weight: bold;
    letter-spacing: 1.25px;
}
#sidebarMenu {
    height: 100%;
    position: fixed;
    right: 0;
    width: 250px;
    margin-top: 60px;
    transform: translateX(+250px);
    transition: transform 250ms ease-in-out;
    background: transparent;
}
.sidebarMenuInner{
    margin:0;
    padding:0;
    border-top: 1px solid rgba(255, 255, 255, 0.10);
}
.sidebarMenuInner li{
    list-style: none;
    color: #fff;
    text-transform: uppercase;
    font-weight: bold;
    padding: 20px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}
.sidebarMenuInner li span{
    display: block;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.50);
}
.sidebarMenuInner li a{
    color: #fff;
    text-transform: uppercase;
    font-weight: bold;
    cursor: pointer;
    text-decoration: none;
}
input[type="checkbox"]:checked ~ #sidebarMenu {
    transform: translateX(0);
}

input[type=checkbox] {
    transition: all 0.6s;
    box-sizing: border-box;
    display: none;
}
.sidebarIconToggle {
    transition: all 0.3s;
    box-sizing: border-box;
    cursor: pointer;
    position: absolute;
    z-index: 99;
    height: 100%;
    width: 100%;
    top: 22px;
    right: 25px;
    height: 22px;
    width: 22px;
}
.spinner {
    transition: all 0.3s;
    box-sizing: border-box;
    position: absolute;
    height: 3px;
    width: 100%;
    background-color: #fff;
}
.horizontal {
    transition: all 0.3s;
    box-sizing: border-box;
    position: relative;
    float: left;
    margin-top: 3px;
}
.diagonal.part-1 {
    position: relative;
    transition: all 0.3s;
    box-sizing: border-box;
    float: left;
}
.diagonal.part-2 {
    transition: all 0.3s;
    box-sizing: border-box;
    position: relative;
    float: left;
    margin-top: 3px;
}
input[type=checkbox]:checked ~ .sidebarIconToggle > .horizontal {
    transition: all 0.3s;
    box-sizing: border-box;
    opacity: 0;
}
input[type=checkbox]:checked ~ .sidebarIconToggle > .diagonal.part-1 {
    transition: all 0.3s;
    box-sizing: border-box;
    transform: rotate(135deg);
    margin-top: 8px;
}
input[type=checkbox]:checked ~ .sidebarIconToggle > .diagonal.part-2 {
    transition: all 0.3s;
    box-sizing: border-box;
    transform: rotate(-135deg);
    margin-top: -9px;
}
.logo-header {
    width:50px;
    position:absolute;
    left: 40%;
    top: 5px;
    z-index: 100;
}
<div class="header"></div>
  <input type="checkbox" class="openSidebarMenu" id="openSidebarMenu">
  <label for="openSidebarMenu" class="sidebarIconToggle">
    <div class="spinner diagonal part-1"></div>
    <div class="spinner horizontal"></div>
    <div class="spinner diagonal part-2"></div>
  </label><a href="https://stackoverflow.com/"><span class="logo-header">
  <img src="https://upload.wikimedia.org/wikipedia/commons/f/fe/CARTOON_NETWORK_logo.png" width=80px> </span> </a>
  <div id="sidebarMenu">
    <ul class="sidebarMenuInner">
      <li><a href="" target="">About</a></li>
      <li><a href="" target="">Conatact</a></li>
      <li><a href="" target="">Support</a></li>
      <li><a href="" target="">Marketing</a></li>
      <li><a href="" target="">About</a></li>
      <li><a href="" target="">Contact</a></li>
      <li>Blog<span>Follow us on Socials</span></li>
    </ul>
  </div>
  <div id='center' class="main center">
    <div class="mainInner">
      <div>Agency</div>
    </div>
    <div class="mainInner">
      <div>Agency</div>
    </div>
    <div class="mainInner">
      <div>Agency</div>
    </div>
  </div>

提前谢谢

1 个答案:

答案 0 :(得分:1)

您可以这样做:

input[type=checkbox]:checked~.sidebarIconToggle~ a > .logo-header {
  left: 0%;
  transition: all 0.3s;
}

还向类transition: all 0.3s;中添加了.logo-header

.logo-header {
  transition: all 0.3s;
  width: 50px;
  position: absolute;
  left: 40%;
  top: 5px;
  z-index: 100;
}

演示

@import url('https://fonts.googleapis.com/css?family=Varela+Round');
html,
body {
  overflow-x: hidden;
  height: 100%;
}

body {
  background-image: url('https://www.3ctele.com/wp-content/uploads/2015/12/3c-gradient-background.png');
  background-size: cover;
  height: 100vh;
  padding: 0;
  margin: 0;
  font-family: 'Varela Round', sans-serif;
}

.header {
  display: block;
  margin: 0 auto;
  width: 100%;
  max-width: 100%;
  box-shadow: none;
  background-color: transparent;
  position: fixed;
  height: 60px!important;
  overflow: hidden;
  z-index: 10;
}

.main {
  margin: 0 auto;
  display: block;
  height: 100%;
  margin-top: 60px;
}

.mainInner {
  display: table;
  height: 100%;
  width: 100%;
  text-align: center;
}

.mainInner div {
  display: table-cell;
  vertical-align: middle;
  font-size: 3em;
  font-weight: bold;
  letter-spacing: 1.25px;
}

#sidebarMenu {
  height: 100%;
  position: fixed;
  right: 0;
  width: 250px;
  margin-top: 60px;
  transform: translateX(+250px);
  transition: transform 250ms ease-in-out;
  background: transparent;
}

.sidebarMenuInner {
  margin: 0;
  padding: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
}

.sidebarMenuInner li {
  list-style: none;
  color: #fff;
  text-transform: uppercase;
  font-weight: bold;
  padding: 20px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}

.sidebarMenuInner li span {
  display: block;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.50);
}

.sidebarMenuInner li a {
  color: #fff;
  text-transform: uppercase;
  font-weight: bold;
  cursor: pointer;
  text-decoration: none;
}

input[type="checkbox"]:checked~#sidebarMenu {
  transform: translateX(0);
}

input[type=checkbox] {
  transition: all 0.6s;
  box-sizing: border-box;
  display: none;
}

.sidebarIconToggle {
  transition: all 0.3s;
  box-sizing: border-box;
  cursor: pointer;
  position: absolute;
  z-index: 99;
  height: 100%;
  width: 100%;
  top: 22px;
  right: 25px;
  height: 22px;
  width: 22px;
}

.spinner {
  transition: all 0.3s;
  box-sizing: border-box;
  position: absolute;
  height: 3px;
  width: 100%;
  background-color: #fff;
}

.horizontal {
  transition: all 0.3s;
  box-sizing: border-box;
  position: relative;
  float: left;
  margin-top: 3px;
}

.diagonal.part-1 {
  position: relative;
  transition: all 0.3s;
  box-sizing: border-box;
  float: left;
}

.diagonal.part-2 {
  transition: all 0.3s;
  box-sizing: border-box;
  position: relative;
  float: left;
  margin-top: 3px;
}

input[type=checkbox]:checked~.sidebarIconToggle>.horizontal {
  transition: all 0.3s;
  box-sizing: border-box;
  opacity: 0;
}

input[type=checkbox]:checked~.sidebarIconToggle>.diagonal.part-1 {
  transition: all 0.3s;
  box-sizing: border-box;
  transform: rotate(135deg);
  margin-top: 8px;
}

input[type=checkbox]:checked~.sidebarIconToggle>.diagonal.part-2 {
  transition: all 0.3s;
  box-sizing: border-box;
  transform: rotate(-135deg);
  margin-top: -9px;
}

input[type=checkbox]:checked~.sidebarIconToggle~a>.logo-header {
  left: 0%;
  transition: all 0.3s;
}

.topMenu{
  list-style:none;
  float:right;
  color:#fff;
  margin-right: -270px;
}
.topMenu li{
  display:inline;
}

input[type=checkbox]:checked~.sidebarIconToggle~.topMenu {
  margin-right: 70px;
  transition: all 0.3s;
}

.logo-header {
  transition: all 0.3s;
  width: 50px;
  position: absolute;
  left: 40%;
  top: 5px;
  z-index: 100;
}
<div class="header"></div>
<input type="checkbox" class="openSidebarMenu" id="openSidebarMenu">
<label for="openSidebarMenu" class="sidebarIconToggle">
  <div class="spinner diagonal part-1"></div>
  <div class="spinner horizontal"></div>
  <div class="spinner diagonal part-2"></div>
</label>
<a href="https://stackoverflow.com/"><span class="logo-header">
  <img src="https://upload.wikimedia.org/wikipedia/commons/f/fe/CARTOON_NETWORK_logo.png" width=80px> </span>
</a>
<ul class="topMenu">
  <li>about us</li>
  <li>contact</li>
  <li>support</li>
</ul>
<div id="sidebarMenu">
  <ul class="sidebarMenuInner">
    <li><a href="" target="">About</a></li>
    <li><a href="" target="">Conatact</a></li>
    <li><a href="" target="">Support</a></li>
    <li><a href="" target="">Marketing</a></li>
    <li><a href="" target="">About</a></li>
    <li><a href="" target="">Contact</a></li>
    <li>Blog<span>Follow us on Socials</span></li>
  </ul>
</div>
<div id='center' class="main center">
  <div class="mainInner">
    <div>Agency</div>
  </div>
  <div class="mainInner">
    <div>Agency</div>
  </div>
  <div class="mainInner">
    <div>Agency</div>
  </div>
</div>