// Wuerfel2.js // 2. version of the Javascript Behaviour for the dice sample control // Copyright (c) by Matthias Hertel, http://www.mathertel.de // This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx // ----- // 03.12.2006 created by Matthias Hertel // 09.01.2007 simpler event handler implementation var WuerfelBehaviour = { rolling: 0, count: 0, onclick: function (evt) { this.rolling = 50; this.count = 0; this.rollNext(); }, rollNext: function () { var o = parseInt(this.innerText); var n = Math.floor(Math.random() * 5) + 1; if (n >= o) n += 1; this.innerText = n; this.rolling *= 1.2; this.count += 1; if (this.count < 10) { this.classList.add("rolling") window.setTimeout("document.getElementById('" + this.id + "').rollNext()", this.rolling); } else { this.classList.remove("rolling") } } // rollNext }; // WuerfelBehaviour
This page is part of the http://www.mathertel.de/ web site.
For updates and discussions see http://ajaxaspects.blogspot.com/.