我正在尝试制作一个扩展为max-height
使用 nanoScroller 和 ngrepeat 的 angularjs 的 div,但我无法使其工作,这是 plunkr: Plunkr。
如果你改变_Array
长度,5
你会明白我在说什么。div 的高度不会根据内容调整......它会停留在max-height
应该缩小以适应的时候。
这是HTML代码:
<div id="console" ng-app="myApp">
<header>Title Here</header>
<section>
<ul ng-init="(_Array = []).length = 15;" class="nano">
<div class="nano-content">
<li ng-repeat="i in _Array track by $index" post-render="">{{ $index }}</li>
</div>
</ul>
</section>
</div>
以及使用 nanoScroller 的指令:
angular.module('myApp', [])
.directive('postRender', postRender);
postRender.$inject = ['$timeout'];
function postRender($timeout) {
return {
link: function ($scope, iElm, iAttrs, controller) {
$timeout(function () {
jQuery('.nano').nanoScroller({
preventPageScrolling: true
})
}, 100);
}
}
}
和我的 SCSS:
* {
box-sizing: border-box;
}
body, html {
height: 100%;
}
#console {
margin: 0 auto;
max-height: 500px;
height: 100%;
width: 330px;
opacity: 0.9;
color: #FFF;
header {
padding: 15px;
background: none repeat scroll 0 0 rgba(21, 21, 21, 0.8);
}
section {
overflow: auto;
background-color: #333;
height: 100%;
ul {
list-style: none;
margin: 0;
padding: 0;
& div {
padding: 15px 15px;
}
li {
margin-bottom: 5px;
width: 100%;
background-color: red;
padding: 15px;
}
}
}
}