Spraycan - vandalise your page
Overview
Spraycan is a pointless if mildly entertaining plugin that allows visitors to treat your site as a graffiti wall. They can paint anywhere on the screen by clicking and dragging the mouse. A tools panel allows them to select the colour and size of the brush. A button to the top right of the screen, put there by the script, closes the plugin and returns to seriousness.
Usage
Simply call spraycan() in a function or link href, and the script does the rest. Everything is DOM-scripted - there's no dependent CSS.
Example
Here's the code behind the example, applied to the button's onclick attribute:
javascript:spraycan();
Notes
Dependencies (none!)
Like most of my scripts, everything is contained and done within the single script file. There is no external CSS to plug in.
Text select issue
Clicking and dragging around the screen always means unwittingly selecting the text on the screen. As far as I know this is unavoidable in everything but IE. IE provides a specialist method for disabling text selection, whereas in Mozilla and other browsers you can only return false from a mousedown event. But that's not really an option for a plugin that listens for mousedown to know when to start painting!
Performance
Since each brush stroke means the appendage of several elements to create the effect, this can cause slow-down if you do a lot of painting, but much depends on the quality of the browser's JS engine and your system. If you want to be on the safe side, change line 229 so the for loop runs only twice, not three times, or even once if you don't care about anti-alias.
Loading jQuery
By default, this script assumes you're loading jQuery via Google (why might you do this?). If, instead, you're loading jQuery from a local copy in your site folder, update the document ready handler (DRH) in the script file:
1//loading jQuery via Google
2google.setonloadcallback(function() { ...
3
4//loading jQuery from local copy (use either)
5$(document).ready(function() {...
6$(function() {...
Comments (9)
Saul, at 17/11/'10 18:27, said:
Ben, at 20/04/'11 23:23, said:
Paudie, at 3/10/'11 22:11, said:
, at 4/10/'11 09:05, said:
Paudie, at 4/10/'11 15:22, said:
Mitya, at 4/10/'11 16:36, said:
Paudie, at 4/10/'11 18:31, said:
Mitya, at 4/10/'11 19:43, said:
Jonas, at 16/12/'11 22:12, said: