Created
July 14, 2015 23:02
-
-
Save mapsam/3f271d4566cc9e3699f3 to your computer and use it in GitHub Desktop.
ImageTalk Experiment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html lang="en"> | |
<head> | |
<title>hello world</title> | |
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> | |
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> | |
<style> | |
body { | |
padding:0; | |
margin:0; | |
} | |
img { | |
width: 100%; | |
height: auto; | |
} | |
.container { | |
position: relative; | |
display: block; | |
} | |
.square { | |
position:absolute; | |
border: 2px solid red; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="container" class="container"><img src="test.png"></div> | |
<script> | |
var ops = { | |
container: 'container', | |
squares: [ | |
{ | |
name: 'Block name', | |
left: 30, | |
top: 8, | |
width: 45, // percentage of the entire screen width | |
height: 10, // percentage of the entire document | |
description: "WAKA FLAKA DESCRIPTION" | |
} | |
] | |
} | |
function init() { | |
window.app = new ImageTalk(ops); | |
} | |
var ImageTalk = function(options) { | |
this.options = options || {}; | |
this.container = document.getElementById(options.container); | |
this.squares = options.squares; | |
this.startTalking(this.squares); | |
} | |
ImageTalk.prototype.startTalking = function(squares) { | |
var _this = this; | |
for (var s = 0; s < squares.length; s++) { | |
_this.container.appendChild(_this.makeOneSquare(squares[s])); | |
} | |
} | |
ImageTalk.prototype.makeOneSquare = function(square) { | |
var s = document.createElement('div'); | |
s.className = 'square'; | |
s.style.left = square.left + '%'; | |
s.style.top = square.top + '%'; | |
s.style.width = square.width + '%'; | |
s.style.height = square.height + '%'; | |
return s; | |
} | |
window.onload = init; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment