Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


<div id="container">
	<span id="counter">0</span>
	<div id="basket"></div>
  <img src="" id="greensock">


                body {
    position: relative;
		overflow: hidden;
		background-color: #000;

#container {

#greensock {
  width: 150px;
  height: 150px;
  position: absolute;

#counter {
    font-size: 95px;
    top: 20px;
    left: 150px;
    color: #fff;
		position: absolute;

.object {
    width: 47px;
    height: 50px;
    left: 0;
    top: 0;
    position: absolute;
    background: url(;
  background-size: cover;

#basket {
    width: 100px;
    height: 40px;
    left: 0;
    bottom: 0;
		background-color: #fff;
		position: absolute;
    z-index: 99;


                var h = window.innerHeight,
		w = window.innerWidth,
		container = document.getElementById("container"),
		objects = 10,
		counter = document.getElementById("counter");

// generate object divs
for (var i = 0; i < objects; i++) {
		var objectDiv = document.createElement('div');
		TweenMax.set(objectDiv, {attr: {class:'object'}, x: R(0,w), y: R(-150,-100) });
// falling objects animations
function startObjectAnim() {
		for (var i = 0; i < objects; i++) {
				var objectDiv = document.getElementsByClassName("object")[i];
				fallingObject(objectDiv, i);
function fallingObject(element, delay) {
var objectTL = new TimelineMax();
		objectTL.set(element, {autoAlpha: 1})
				 		.to(element, R(3,6), {y: h+50, ease: Linear.easeNone, onUpdate:checkHit, onUpdateParams: [element], repeat:-1, delay: delay*1.5});
// randomize function
function R(min,max) {return min+Math.random()*(max-min)};
// check for collision   
function checkHit(element) {
	var selectObject = element;
	if (Draggable.hitTest(basket, selectObject, "80%") ) {
		TweenMax.set(selectObject, {autoAlpha: 0});
			if (parseInt(counter.textContent) < objects ) {
				counter.textContent = parseInt(counter.textContent) + 1;
// function if you want to run some animation after game finishes
function checkHowManyCaught() {
	var getCounter = parseInt(counter.textContent);
		if (getCounter === objects) {
			// your code

// stop objects animation and reset to starting positions
function killAllObjects() {
	for (var i=0; i<10; i++) {
		var killedObjects = document.getElementsByClassName("object")[i];
		TweenMax.set(killedObjects, {autoAlpha: 0});
		TweenMax.set(killedObjects, {x: R(50,w), y: R(-150,-100) });

// Move basket on mouse move        
var basket = document.getElementById("basket");
var enabled = false;
var max  = w - basket.offsetWidth / 2;

function moveBasket(e) {
	var x = e.clientX;
		if (x > max) {
				x = max;
		TweenMax.set(basket, {xPercent: -50});, 0.5, {x: x, ease: Power1.easenone});
function moveBasketBack() { 
	container.removeEventListener("mousemove", moveBasket);
	enabled = false;
function enableMovement() {
	if (enabled) return;
			enabled = true;
			container.addEventListener("mousemove", moveBasket);
container.addEventListener("mouseenter", enableMovement);
container.addEventListener("mouseleave", moveBasketBack);