简体   繁体   English

用y强制div始终显示最新(div的底部)

[英]Force div with overflow-y to always show newest (bottom of div)

I have created an action-log which is supposed to keep you up to date about your actions. 我创建了一个操作日志,该日志应该使您了解最新的操作。 So everytime you click on the button it shows you what you just did, but the problem is that it won't show the newest message automatically. 因此,每次您单击按钮时,它都会向您显示您刚刚做的事情,但是问题在于它不会自动显示最新消息。 Is it possible to show the newest message everytime you click on the button? 每次单击按钮是否可以显示最新消息?

JSfiddle: https://jsfiddle.net/a8ey2ucm/1/ JSfiddle: https ://jsfiddle.net/a8ey2ucm/1/

<div id="log">

</div>

<button onclick="actionBtn();">
  Click here
</button>

function actionBtn()
{
    var log = document.getElementById('log');
  var action = document.createElement("p");
  var actionNode = document.createTextNode("You have rolled");

  action.appendChild(actionNode);
  log.appendChild(action);
} 

I guess there are countless answers for this on the web. 我猜网上有无数答案。 However 然而

function actionBtn()
{
    var log = document.getElementById('log');
    var action = document.createElement("p");
    var actionNode = document.createTextNode("You have rolled");

    action.appendChild(actionNode);
    log.appendChild(action);

    log.scrollTop = log.scrollHeight;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM