我试图使用HTML、css和angularjs创建flexbox可折叠菜单-可折叠菜单功能运行良好,但css转换效果在内容较大时不起作用(例如:使用"Lorem Ipsum"文本块(-当"Lorem Ipsum"文字块不存在时,它运行良好,我找不到相同的原因。提前感谢您的帮助。
Plnkr演示
var app = angular.module('app', []);
app.controller('myctrl', function($scope) {
$scope.toggle = function() {
angular.element(document.querySelector('.sidebar')).toggleClass('isClosed');
angular.element(document.querySelector('.hideButton')).toggleClass('isClosed');
angular.element(document.querySelector('.sidebar ul.nav')).toggleClass('isClosed');
}
})
/*
* ==== RESETS ====
*/
* {
margin: 0;
padding: 0;
}
*,
*:before,
*:after {
box-sizing: border-box;
}
/*
* ==== IMPORTS ====
*/
/*
* ==== STYLING ====
*/
html,
body {
height: 100%;
}
body {
font-family: -apple-system, ".SFNSText-Regular", "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", sans-serif;
}
.wrapper {
display: flex;
height: 100%;
padding: 20px;
}
.hideButton {
display: flex;
min-height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.hideButton a {
border: 1px solid;
border-radius: 2px;
}
/*
* ==== SIDEBAR ====
*/
.sidebar {
display: flex;
min-height: 100%;
flex-grow: auto;
transition: all linear 0.3s;
border: 1px solid;
border-radius: 5px;
padding: 5px;
}
.sidebar.isClosed {
flex-grow: 0;
border: none;
}
.sidebar ul.nav {
display: flex;
flex-direction: column;
width: 100%;
opacity: 1;
}
.sidebar ul.nav.isClosed {
display: none;
}
.sidebar ul.nav li {
list-style: none;
padding: 20px 0;
border: 1px solid #ccc;
border-radius: 5px;
margin: 2px 0;
}
.sidebar ul.nav li a {
display: block;
text-decoration: none;
color: #666;
text-align: center;
padding: 0 2px;
}
.sidebar ul.nav li a:hover {
color: #000;
}
.sidebar div {
max-width: 180px;
}
/*
* ==== CONTENT ====
*/
.content {
min-height: 100%;
flex-grow: 9;
padding: 40px;
transform: translate3d(0, 0, 0);
transition: transform 0.3s;
}
/*
* ==== TOGGLE BUTTON ====
*/
a.button {
cursor: pointer;
/* position: absolute;
top: 10px;
left: 10px;*/
display: block;
}
a.button:before {
font-weight: bold;
font-size: 20px;
content: "<";
transition: content linear 1s;
}
.isClosed a.button::before {
content: '>';
transition: content linear 1s;
}
/*
* ==== MEDIA QUERIES ====
*/
@media only screen and (max-device-width: 736px) and (orientation: portrait) {
.wrapper {
flex-direction: column;
}
.sidebar {
min-height: 60px;
max-height: 60px;
}
.sidebar ul.nav {
padding: 20px;
flex-direction: row;
}
.sidebar ul.nav li {
display: inline-block;
padding: 2%;
}
.content {
/*TBD*/
}
.content a.button {
display: none;
}
}
<!DOCTYPE html>
<html ng-app="app">
<head>
<script data-require="angular.js@*" data-semver="4.0.0" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.10/angular.min.js"></script>
<script data-require="angular.js@*" data-semver="4.0.0" src="script.ts"></script>
<script data-require="angular.js@*" data-semver="4.0.0" src="system.config.js"></script>
<script data-require="angular.js@*" data-semver="4.0.0" src="tsconfig.json"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-controller="myctrl">
<div id="wrapper" class="wrapper">
<div id="aside" class="sidebar">
<div>
<ul class="nav">
<li><a href="#">Home</a></li>
<li><a href="#">Experience is the key of the item of the rest of the kind</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Bio</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
<!-- /Aside -->
<div class="hideButton">
<div class="Aligner">
<a class="button" ng-click="toggle()"></a>
</div>
</div>
<div id="content" class="content">
<h1>Flexbox Off-Canvas Side Menu</h1>
<h2>Easy to use</h2>
<div>
What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more
recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The
point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem
Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). Where
does it come from? Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College
in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and
1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit
amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in
their exact original form, accompanied by English versions from the 1914 translation by H. Rackham. Where can I get some? There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by
injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators
on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which
looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
</div>
</div>
<!-- /Content -->
</div>
</body>
</html>
<!DOCTYPE html>
<html ng-app="app">
<head>
<script data-require="angular.js@*" data-semver="4.0.0" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.10/angular.min.js"></script>
<script data-require="angular.js@*" data-semver="4.0.0" src="script.ts"></script>
<script data-require="angular.js@*" data-semver="4.0.0" src="system.config.js"></script>
<script data-require="angular.js@*" data-semver="4.0.0" src="tsconfig.json"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-controller="myctrl">
<div id="wrapper" class="wrapper">
<div id="aside" class="sidebar">
<div>
<ul class="nav">
<li><a href="#">Home</a></li>
<li><a href="#">Experience is the key of the item of the rest of the kind</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Bio</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
<!-- /Aside -->
<div class="hideButton">
<div class="Aligner">
<a class="button" ng-click="toggle()"></a>
</div>
</div>
<div id="content" class="content">
<h1>Flexbox Off-Canvas Side Menu</h1>
<h2>Easy to use</h2>
<div>
What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and
more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.
The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use
Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Where does it come from? Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney
College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections
1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum
dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced
in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham. Where can I get some? There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form,
by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators
on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum
which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
</div>
</div>
<!-- /Content -->
</div>
</body>
</html>
/*
* ==== RESETS ====
*/
* {
margin: 0;
padding: 0;
}
*,
*:before,
*:after {
box-sizing: border-box;
}
/*
* ==== IMPORTS ====
*/
/*
* ==== STYLING ====
*/
html,
body {
height: 100%;
}
body {
font-family: -apple-system, ".SFNSText-Regular", "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", sans-serif;
}
.wrapper {
display: flex;
height: 100%;
padding: 20px;
}
.hideButton {
display: flex;
min-height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.hideButton a {
border: 1px solid;
border-radius: 2px;
}
/*
* ==== SIDEBAR ====
*/
.sidebar {
display: flex;
min-height: 100%;
flex-grow: auto;
transition: all linear 5s;
border: 1px solid;
border-radius: 5px;
padding: 5px;
opacity: 1;
}
.sidebar.isClosed {
flex-grow: 0;
border: none;
opacity: 0;
}
.sidebar ul.nav {
display: flex;
flex-direction: column;
width: 100%;
opacity: 1;
transition: all linear 5s;
}
.sidebar ul.nav.isClosed li {
display: none;
}
.sidebar ul.nav li {
list-style: none;
padding: 20px 0;
border: 1px solid #ccc;
border-radius: 5px;
margin: 2px 0;
transition: all linear 5s;
}
.sidebar ul.nav li a {
display: block;
opacity:1;
text-decoration: none;
color: #666;
text-align: center;
padding: 0 2px;
transition: all linear 5s;
}
.sidebar ul.nav.isClosed li a{
display:none;
opacity:0;
}
.sidebar ul.nav li a:hover {
color: #000;
}
.sidebar div {
max-width: 180px;
}
/*
* ==== CONTENT ====
*/
.content {
min-height: 100%;
flex-grow: 9;
padding: 40px;
transform: translate3d(0, 0, 0);
transition: transform 5s;
}
/*
* ==== TOGGLE BUTTON ====
*/
a.button {
cursor: pointer;
/* position: absolute;
top: 10px;
left: 10px;*/
display: block;
}
a.button:before {
font-weight: bold;
font-size: 20px;
content: "<";
transition: content linear 1s;
}
.isClosed a.button::before {
content: '>';
transition: content linear 1s;
}
/*
* ==== MEDIA QUERIES ====
*/
@media only screen and (max-device-width: 736px) and (orientation: portrait) {
.wrapper {
flex-direction: column;
}
.sidebar {
min-height: 60px;
max-height: 60px;
}
.sidebar ul.nav {
padding: 20px;
flex-direction: row;
}
.sidebar ul.nav li {
display: inline-block;
padding: 2%;
}
.content {
/*TBD*/
}
.content a.button {
display: none;
}
}
var app = angular.module('app', []);
app.controller('myctrl', function($scope) {
$scope.toggle = function() {
angular.element(document.querySelector('.sidebar')).toggleClass('isClosed');
angular.element(document.querySelector('.hideButton')).toggleClass('isClosed');
angular.element(document.querySelector('.sidebar ul.nav')).toggleClass('isClosed');
}
})