Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Mutation Observer test</title>
  <script src="//cdn.jsdelivr.net/mootools/1.4.5/mootools-core-1.4.5-full-nocompat-yc.js"></script>
  <script src="//rawgit.com/megawac/MutationObserver.js/master/MutationObserver.js"
  ></script>
  <script src="//rawgit.com/mootools/mootools-more/992345a159b357cf06635f3060ba3179e1bb7074/Source/Fx/Fx.Scroll.js"></script>
  <script src="//rawgit.com/f/loremjs/ec971d2c7fc9a9b6a788095e0523a2794420f5c4/lorem.js"></script>
</head>
<body>
  <div id="description">
    <p>
      This is a simple sample use of the Mutation Observer interface. Every 2 seconds a new articile will be created with some dummy lorem and the mutation observer will scroll the container according to content.
    </p>
  </div>
  <div id="container"></div>
</body>
</html>
 
#container {
  overflow: scroll;
  height: 500px;
}
 
$(document).addEvent("domready", function() {
    "use strict";
    var lorem = new Lorem();
    lorem.type = Lorem.TEXT;
    lorem.query = '1p';
    var $container = document.getElementById("container");
    var scroller = window.scroller = new Fx.Scroll($container, {});
    var observer = new MutationObserver(function(mutations){
        if(console) console.log("new content");
        scroller.toBottom();
        //scroller.set($container.scrollLeft, $container.scrollHeight); //place at bottom instantly
    });
    observer.observe($container, {
        childList: true
    });
    setInterval(function() {
        var $par = new Element("div", {
            "class": 'article'
        }).inject($container);
        var $art = new Element("p", {
            "class": "summary"
        }).inject($par);
        lorem.createLorem($art);
    }, 2000);
});
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers