Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bmiedlar
Forked from 140bytes/LICENSE.txt
Created May 19, 2011 22:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmiedlar/981915 to your computer and use it in GitHub Desktop.
Save bmiedlar/981915 to your computer and use it in GitHub Desktop.
Screensaver

Bringing back the screensaver! It would support IE but I ran out of bytes. This requires an absolutely positioned element in order to work (as the collision box).

function(
a, //References an absolutely positioned collision box style property
b, //The width to use for the collision box
c, //The height to use for the collision box
d, //Starting x coordinate and placeholder for x coordinate of the box
e, //Starting y coordinate and placeholder for x coordinate of the box
j //Interval to redraw the box
){function h(){ //Redraw the box
a.left= //Set the x coordinate
(d+= //by adding or subtracting it to the current x coordinate
b*= //by adding or subtracting the box width
d<0|d>innerWidth?-1:1) //by checking if it is still inside the viewport and multiplying in the appropriate direction
+'px'; //and then setting the coordinate to the style property
a.top= //Set the y coordinate
(e+= //by adding or subtracting it to the current y coordinate
c*= //by adding or subtracting the box height
e<0|e>innerHeight?-1:1) //by checking if it is still inside the viewport and multiplying in the appropriate direction
+'px' //and then setting the coordinate to the style property
}setInterval(h,j) //and then calling a redraw to move the box at the given interval
}
<html>
<body>
<div id="ScreenSaver" style="position:absolute;">
<img width="100" height="100" alt="" src="http://mied.la/images/ss140.gif">
<p>My Screensaver</p>
</div>
<script>
var showScreenSaver = function(a,b,c,d,e,j){function h(){a.left=(d+=b*=d<0|d>innerWidth?-1:1)+'px';a.top=(e+=c*=e<0|e>innerHeight?-1:1)+'px'}setInterval(h,j)}
showScreenSaver(document.getElementById('ScreenSaver').style, 100, 100, 100, 100, 350);
</script>
</body>
</html>
function(a,b,c,d,e,j){function h(){a.left=(d+=b*=d<0|d>innerWidth?-1:1)+'px';a.top=(e+=c*=e<0|e>innerHeight?-1:1)+'px'}setInterval(h,j)}
Copyright (c) 2011 Brian Miedlar, mied.la
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "Screensaver",
"description": "Moving an element around the screen as expected in a simple screensaver",
"keywords": [
"screensaver"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment