Again, working on a Chrome extension here. This time, I'm looking to make a transparent png appear at a random place within the window. I feel like I could somehow use jQuery .animate() somehow? I would like to make the image appear somewhere random on the screen, or have it appear on top of a random element on the screen, be it text of an image etc. I have not an idea where to even begin. Any ideas? All input appreciated! EDIT: Here is my image.js file:
var image = "image";
chrome.extension.getURL('image.png');
$(document).ready(function(){
randomlyMoveImage();
});
$("#image").css({
"position": "absolute",
});
$("#image").attr("src", image.png);
function randomlyMoveImage(){
var width = $(document).width();
var height = $(document).height();
var x = Math.floor((Math.random() * width) + 1);
var y = Math.floor((Math.random() * height) + 1);
$( "#image" ).animate({
left: x,
top: y
}, 0, function() {
// Animation complete.
});
setTimeout(randomlyMoveImage, 3000);
}
$("#image").css({
"position": "absolute",
});
and here is my manifest.json:
{
"manifest_version": 2,
"name": "Animation",
"description": "Animation",
"version": "1.0",
"web_accessible_resources": ["image.png"],
"browser_action": {
"default_icon": "image.png",
"default_title": "Animation"
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["jquery.min.js"]
}
],
"background": {
"scripts": ["extensionListener.js","audio.js"],
"persistent": false
},
"permissions": [
"activeTab",
"https://ajax.googleapis.com/"
]
}
Chrome inspect element returns that there is an error on image.js line 3, saying "$ is not defined". Any help is appreciated.