<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 xKeyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |