Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="">
- <head>
- <meta charset="utf-8">
- <!--
- <link rel="stylesheet" href="wait.css" />
- -->
- <style>
- #container{
- background-color: beige;
- position: absolute;
- bottom:0;
- top:0;
- left:0;
- right:0;
- }
- .animate_container{
- margin:auto;
- width:100%;
- height:100%;
- background-color:beige;
- text-align:center;
- cursor:pointer;
- }
- .animate_container .circle{
- background-color: lightgray;
- width:1rem;
- height:1em;
- margin-left:1em;
- margin-right:1em;
- display:inline-block;
- transition:1s;
- border-radius:0.5em;
- }
- .animate_container .active{
- background-color:brown;
- box-shadow: 0px 0px 5px 5px brown;
- }
- </style>
- <script>
- var dom = document;
- var vom = {};
- dom.get_s = document.querySelectorAll;
- function Elem(type_name, txt, css_cls){
- var elem = document.createElement(type_name);
- elem.innerText = txt; //value
- if (css_cls) {
- elem.className = css_cls;
- }
- return elem;
- }
- vom.add = function(container, elem, cls)
- {
- if (typeof container == 'string') {
- container = document.querySelector(container);
- }
- if (typeof elem == 'string'){
- elem = document.createElement(elem);
- if (cls) elem.className = cls;
- }
- container.appendChild(elem);
- return elem;
- };
- HTMLElement.prototype.vs = function (dict) {
- for (var key in dict){
- this.setAttribute(key, dict[key]);
- }
- return this;
- };
- var animate = {
- elem_quantity : 5,
- time_wait : 500,
- animates : [],
- stop : function(){
- for(var i=0;i<animates.length;i++){
- clearInterval(this.animates[i]);
- }
- this.animates = [];
- },
- start : function(elem){
- var anim =
- vom.add(elem,'div','animate_container'
- );
- var i=0; while(i<animate.elem_quantity){
- vom.add(anim, 'div', 'circle');
- }
- return wait_animate(anim);
- }
- }
- var animate_start = function(elem){
- var anim =
- vom.add(elem,'div','animate_container'
- );
- var i=0; while(i<animate.elem_quantity){
- vom.add(anim, 'div', 'circle');
- }
- return wait_animate(anim);
- }
- function wait_animate(elem){
- _time = animate.time_wait || 500;
- var elems=(elem || dom).querySelectorAll(
- '.animate_container .circle'
- );
- var key = 0;
- var _animate = setInterval(function(){
- var len = elems.length - 1;
- if (len < 0)
- throw new Error ('missing elements inside container for animate');
- var pre = key > 0 ? key - 1 : len;
- elems[key].className = 'circle active';
- elems[pre].className = 'circle';
- if (key<len) {key+=1} else key=0;
- }, _time);
- animate.animates.push(_animate);
- return _animate;
- }
- </script>
- </head>
- <body>
- <div id="container" onclick='animate_start(this)'>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement