CAU-Web-Fall-2018-Project-1/static/js/javascript.js

108 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-12-13 01:18:24 +00:00
let pointConfig = [
{
title: "Test",
top: 45,
left: 80,
},
{
title: "Test3",
top: 125,
left: 53,
},
{
title: "Test4",
top: 85,
left: 170,
},
{
title: "Test5",
top: 115,
left: 121,
},
];
2018-12-12 06:04:47 +00:00
2018-12-13 01:18:24 +00:00
let Point = ( function () {
2018-12-12 06:04:47 +00:00
2018-12-13 01:55:35 +00:00
let Point = function ( conf, callback ) {
2018-12-13 01:18:24 +00:00
this.config = conf;
2018-12-13 01:55:35 +00:00
this.callback = callback;
2018-12-13 01:18:24 +00:00
this.addSpecificCSS();
this.adHtml();
};
let proto = Point.prototype;
proto.addSpecificCSS = function () {
console.log( "Point addSpecificCSS" );
let css = `<style id="point-css">`;
for ( let conf of this.config ) {
css += `
.${ conf.title }-css {
animation: ${ conf.title }-animation 1s linear 0s infinite normal none running;
top: ${ conf.top }px;
left: ${ conf.left }px;
}
.${ conf.title }-css.stop {
animation: none;
}
@keyframes ${ conf.title }-animation {
0% {
width: 10px;
height: 10px;
top: ${ conf.top }px;
left: ${ conf.left }px;
}
50% {
width: 20px;
height: 20px;
top: ${ conf.top - 5 }px;
left: ${ conf.left - 5 }px;
}
100% {
width: 10px;
height: 10px;
top: ${ conf.top }px;
left: ${ conf.left }px;
}
}`;
}
css += `</style>`;
if ( $( "#point-css" ).length === 0 ) {
$( "head" ).append( css.replace( / |\n/g, "" ) );
}
};
proto.adHtml = function () {
let container = $( "#point-container" );
let html = ``;
for ( let conf of this.config ) {
html += `<div class="blue darken-3 point ${ conf.title }-css ${ conf.noAnim ? "stop" : "" }"></div>`;
}
container.append( html.replace( / |\n/g, "" ) );
2018-12-13 01:55:35 +00:00
this.callback( this );
2018-12-13 01:18:24 +00:00
};
proto.start = function () {
2018-12-13 01:55:35 +00:00
let container = $( "#point-container" );
2018-12-13 01:18:24 +00:00
2018-12-13 01:55:35 +00:00
container.addClass( "start" );
2018-12-13 01:18:24 +00:00
};
return Point;
}() );
$( document ).ready( () => {
$( ".dropdown-trigger" ).dropdown();
2018-12-13 01:55:35 +00:00
let point;
new Point( pointConfig, ( p ) => {
point = p;
point.start();
} );
2018-12-13 01:18:24 +00:00
} );