我正在使用ng-repeat来显示一些消息,并且正在尝试使“ message_area”可滚动,因为随着时间的推移,消息自然会导致溢出,但是我的代码无法正常工作。

<div class="main_area">

  <div id = "message_area" ng-repeat = "message in selected_conversation_object.messages.slice().reverse()">
    <div class="message_container" ng-if = "message.sender != me._id">
      <div class="message_received">{{message.message}}</div>
    </div>
    <div class="message_container" ng-if = "message.sender == me._id">
      <div class="message_sent_by_me">{{message.message}}</div>
    </div>
  </div>

</div>

.main_area {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 325px;
  right: 0;
  height: 100%;
  background: white;
}

#message_area {
  position: relative;
  overflow-y: scroll;
}

.message_container {
  position: relative;
  width: 100%;
  height: 30px;
}

.message_received {
}

.message_sent_by_me {
  position: relative;
  background-color: #0084FF;
  border-radius: 5px;
  width: 100px;
  color: white;
  float: right;
}


我无法理解为什么我的代码无法正常工作。

任何建议,将不胜感激。

最佳答案

您需要为min-height选择器设置#message_area

#message_area {
   position: relative;
   min-height: 50px; // Add This.
   overflow-y: scroll;
}

关于javascript - 使用ng-repeat时使div可滚动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34472019/

10-10 19:16