var location_data_ready = false;
var image;
var contex;
function mouse_over(tag_id) {
if (location_data_ready) {
addBox(tag_id);
}
}
function mouse_out(tag_id) {
if (location_data_ready) {
removeBox(tag_id);
}
}
function addBox(tag_id) {
// show the overlay
context.fillStyle = "rgba(0, 0, 0, 0.6)";
context.fillRect(0, 0, image.width, image.height);
// put a hole in the oeverlay - method 1
context.clearRect(50,50, 30,30);
// put another hole in the overlay - method 2
context.fillStyle = "rgbs(0,0,0,0)";
context.fillRect(200,200,30,30);
// add somew text
context.font = "30px Arial";
context.fillStyle = "red";
context.fillText("Hello World", 200, 235);
console.log("Finished adding the overlay with cutouts");
}
function removeBox(tag_id) {
context.clearRect(0, 0, image.width, image.height);
console.log("Finished removing the overlay")
}
$(document).ready(function(){
console.log("Image width="+$( "#img1" ).width()+", height="+$( "#img1" ).height());
// ajax code to get locations from the server - rmeoved for clarity on the issue
// First, grab the face locations and scale_factor from the server
scale_factor = 1;
image = document.getElementById("img1");
// now set up the canvas overlay
position = $("#img1").position();
canvas = document.getElementById("overlay");
context = canvas.getContext("2d");
canvas.style.left = position.left + "px";
canvas.style.top = position.top + "px";
canvas.style.width = image.width + "px";
canvas.style.height = image.height + "px";
context.fillStyle = "rgba(0, 0, 0, 0)";
location_data_ready = true;
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.