gpt4 book ai didi

javascript - 如何让我的侧边菜单插入其他元素切换?

转载 作者:行者123 更新时间:2023-11-28 16:08:36 24 4
gpt4 key购买 nike

我无法让侧边菜单在切换侧边菜单时将其他元素推开(按侧边菜单的相同宽度)。我希望侧边菜单在滑入时将相邻元素推开。非常感谢,这是我的代码。

$(document).ready(function() {

$("#hamburger").click(function() {
$("header nav").animate({width: 'toggle'});
});
$("header nav").mouseleave(function() {
$("header nav").animate({width: 'toggle'});
});
});
/* Universal Styles */

* {
box-sizing: border-box;
}
body {
text-align: center;
}
a {
text-decoration: none;
color: inherit;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin: 0;
padding: 0;
}

/* Cross Styles */

aside,
.navBlock {
font-family: 'Bungee Inline', cursive;
}

/* Header Styles */

.logo {
width: 150px;
cursor: pointer;
transition: all .2s;
float: left;
margin-bottom: 10px;
}
nav,
header{
overflow: auto;
width: 100%;
}

#hamburger {
float: right;
transition: all .2s;
cursor: pointer;
}
/* Navigation Styles */

header nav {
position: absolute;
width: 50%;
top: 0;
height: 100%;
background-color: #354551;
margin: 0;
box-shadow: inset 0px 0px 12px 2px rgba(0,0,0,0.75);
display: none;
z-index: 100;
}
.navBlock {
background-color: #354551;
text-transform: uppercase;
font-size: 2em;
color: white;
letter-spacing: 3px;
border: none;
cursor: pointer;
line-height: 175%;
transition: all .2s;
}
header nav ul {
box-shadow: 0px 0px 5px 1px rgba(0,0,0,0.75);
margin-top: 50%;
border-top: 1px dashed lightgrey;
border-bottom: 1px dashed lightgrey;
}

/* Profiles Styles */

aside ul,
aside li,
aside {
overflow: auto;
}
aside {
background-color: #90afc5;
box-shadow: inset 0px 20px 9px -22px #000;
color: #eef3f6;
font-size: 1.5em;
letter-spacing: 2px;
text-shadow: 0px 1px 1px #4d4d4d;
width: 100%;
}
aside li {
display: inline;
}
aside img {
border-radius: 100%;
transition: all .2s;
}

/* Footer Styles */

footer {
font-family: 'Oswald', cursive;
letter-spacing: 1px;
font-size: .9em;
height: 25px;
background-color: #abc3d3;
color: #2c4354;
}
footer span {
line-height: 25px;
}

/* Showcase */

main h4 {
margin-top: 30px;
color: white;
font-size: 2em;
letter-spacing: 2px;
text-shadow: 0px 1px 1px #4d4d4d;
font-family: 'Bungee Inline', cursive;
border: 10x dashed lightgray;
box-shadow: 0px -20px 9px -22px #000;
}
.webShowcase img,
.logoShowcase img {
width: 80%;
margin: 50px auto;
transition: all .3s;
border: 1px solid lightgrey;
}
.webShowcase h4 {
background-color: #ffbb00;
margin: 0;
}
.webShowcase ul,
.logoShowcase ul {
margin-top: 30px;
text-align: center;
}
.webShowcase ul,
.webShowcase li,
.webShowcase,
.logoShowcase,
.logoShowcase li,
.logoShowcase ul {
overflow: auto;
}
.webShowcase,
.logoShowcase {
width: 100%;
}
.logoShowcase h4 {
background-color: #aebd38;
margin: 0;
}

/* Effects */

aside img:hover,
.logo:hover,
.navBlock:hover,
#hamburger:hover,
main img:hover {
opacity: .5;
}

/* Tablet View */

@media only screen and (min-width: 767px) {
aside ul {
margin-bottom: 10px;
}
}
/* Computer View */

@media only screen and (min-width: 1200px) {
.logo {
width: 250px;
}
#hamburger {
content: url("../media/img/hamburgerResized.png");
}
header nav {
width: 25%;
}
.webShowcase img,
.logoShowcase img {
width: 30%;
display: inline-block;
}
.webShowcase li,
.webShowcase,
.webShowcase ul,
.logoShowcase,
.logoShowcase li,
.logoShowcase ul {
overflow: auto;
}
.webShowcase li,
.logoShowcase li {
display: inline;
margin: 0 10px;
padding: 0;
}
.webShowcase ul,
.logoShowcase ul {
margin: 0;
padding: 0;
}
.webShowcase ul:nth-child(odd) {
background-color: #ffcf4d;
}
.webShowcase ul:nth-child(even) {
background-color: white;
}
.logoShowcase ul:nth-child(odd) {
background-color: #c3d062;
}
.logoShowcase ul:nth-child(even) {
background-color: white;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Alexander Palermo-Wylde | Portfolio</title>
<link href='https://fonts.googleapis.com/css?family=Sigmar+One|Seymour+One|Monofett|Faster+One|Rye|Eczar|Bungee+Inline|Miltonian+Tattoo|Oswald' rel='stylesheet' type='text/css'>
<link href="../../css/normalize.css" rel="stylesheet" type="text/css">
<link href="../../css/main.css" rel="stylesheet" type="text/css">
<meta content="index, follow" name="robots">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<meta charset="utf-8">
<meta content="An awesome portfolio. Nuff said." name="Description">
<meta content="portfolio, freelance, freelancer, web design, web development, alexander palermo-wylde, alexander pw" name="Keywords">
</head>
<body>
<header>
<a href="../../index.html"><img class="logo" src="../../media/img/logo.png" alt="Alexander Palermo-Wylde's logo"></a>
<img id="hamburger" src="../../media/img/hamburger.png" alt="three line navigation">
<nav>
<ul>
<li class="navBlock navHome"><a href="../../index.html">home</a></li>
<li class="navBlock navAbout"><a href="../pages/about/index.html">about</a></li>
<li class="navBlock navContact"><a href="../pages/contact/index.html">contact</a></li>
<li class="navBlock navResume"><a href="../pages/resume/index.html">resume</a></li>
</ul>
</nav>

<main>
<section class="webShowcase">
<h4>Websites</h4>
<ul>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
</ul>
<ul>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
</ul>
<ul>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
</ul>
</section>
<section class="logoShowcase">
<h4>Logos</h4>
<ul>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
</ul>
<ul>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
</ul>
<ul>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
<li><a href=""><img src="../../media/img/web-showcase01.png"></a></li>
</ul>
</section>
</main>

<aside>
<h4>Check me out on─</h4
<ul>
<li><a href="#"><img class="profiles" src="../../media/img/github.png" alt="Alexander Palermo-Wylde's GitHub profile link"></a></li>
</div>
<li><a href="#"><img class="profiles" src="../../media/img/codepen.png" alt="Alexander Palermo-Wylde's CodePen profile link"></a></li>
</div>
<li><a href="#"><img class="profiles" src="../../media/img/linkedin.png" alt="Alexander Palermo-Wylde's LinkedIn profile link"></a></li>
</div>
<li><a href="#"><img class="profiles" src="../../media/img/dribble.png" alt="Alexander Palermo-Wylde's Dribble profile link"></a></li>
</div>
<li><a href="#"><img class="profiles" src="../../media/img/upwork.png" alt="Alexander Palermo-Wylde's Upwork profile link"></a></li>
</div>
<li><a href="#"><img class="profiles" src="../../media/img/fiverr.png" alt="Alexander Palermo-Wylde's Elance profile link"></a></li>
</div>
</ul>
</div>
</aside>
</header>
<footer>
<span>&copy;Alexander Palermo-Wylde</span>
</footer>
<script src="http://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script src="../../js/main.js"></script>
</body>
</html>

最佳答案

添加这个JQuery:

$(document).ready(function() {
$("#hamburger").click(function() {
$(".fixed").toggleClass('show');
$('main').toggleClass('fixed-active');
$('header').toggleClass('fixed-active');
});
});

这个CSS:

.fixed {
position: fixed;
width: 300px;
top: 0;
left: 0;
height: 100%;
background-color: #354551;
margin: 0;
box-shadow: inset 0px 0px 12px 2px rgba(0,0,0,0.75);
z-index: 100;
left: -100%;
transition: all .3s ease-in;
}
.fixed.show{
left:0;
}
main, header {
transition: all .3s ease-in;
}
main.fixed-active, header.fixed-active {
padding-left: 300px;
position: relative;
}

查看fiddle
希望这对您有所帮助!

关于javascript - 如何让我的侧边菜单插入其他元素切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38681350/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com