Monday, 12 January 2015

Pixel Bunny: Growing and Shrinking Objects with Offset and Client

Pixel Bunny

Grow or shrink the bunny!

The code does not work within this blog so please save the code on your desktop and try it out.
I was mindlessly doodling around on a Sunday afternoon when I had the idea to make a bunny with CSS and grow and shrink it with JavaScript.

The whole bunny is designed just with CSS. I won't go into details so please have a looksee at the code below.

I thought, I want to grow and shrink that little bunny. Yes, sounds like we need JavaScript. Growing and shrinking the body of the bunny means in other words adding pixels to it.

A perfect object for that are the 2 event objects offsetX and clientX. ClientX outputs the x-coordinate of the mouse pointer on the screen. For example, if you put the mouse on the top left corner of the browser the coordinate will be x = 0. OffsetX returns the x-coordinate of the div element.

Since it is an event object you have to write "event" inside the expression of the function otherwise nothing will fire. In the example it is "change(event)". The event is triggered when the move is moved horizontally.







HTML, CSS and JavaScript Code

The code below has to be saved as a .html file!

No comments:

Post a Comment