Rainbow Drops

Developer
Size
2,365 Kb
Views
46,552

How do I make an rainbow drops?

Randomly generated drops that fall and 'splatter' with gravity.Update: Added transparency based on fall height.. What is a rainbow drops? How do you make a rainbow drops? This script and codes were developed by Chris Barnes on 11 August 2022, Thursday.

Rainbow Drops Previews

Rainbow Drops - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Rainbow Drops</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="tank">
<div id="box"></div>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Rainbow Drops - Script Codes CSS Codes

body{
background-color:#fff;
}
#tank{ height:100px; width:500px; margin:0 auto; position:relative;
}
#box{ background-color:#000; position:absolute; top:102px; height:100px; width:100%; border-radius:5px;
}
span{ position:absolute; height:5px; width:5px; border-radius:10px; box-shadow:1px 1px 5px 1px rgba(0,0,0,.5);
}
.red{ background-color:#d94253
}
.orange{ background-color:#ff9900;
}
.green{ background-color:#73d932;
}
.blue{ background-color:#0099ff;
}
.purple{ background-color:#5309d2;
}

Rainbow Drops - Script Codes JS Codes

setInterval(function(){ var newDrop = document.createElement('span'); var drop_x = Math.floor(Math.random()*495+1); var drop_y = Math.floor(Math.random()*100+1); var temp = $(newDrop).appendTo('#tank').css({ left : drop_x + 'px', top : drop_y + 'px' }); if(drop_x < 100) { temp.addClass('red'); } else if(drop_x < 200) { temp.addClass('orange'); } else if(drop_x < 300) { temp.addClass('green'); } else if(drop_x < 400) { temp.addClass('blue'); } else if(drop_x < 500) { temp.addClass('purple'); } doStuff(temp, drop_y);
}, parseInt(($('#tank').children().length)/.01));
function doStuff(temp, drop_y){ var gravity = .1; var curr_speed = 1; var timer; timer = setInterval(function() { var pos = temp.position(); if(pos.top <= 97) { curr_speed += curr_speed * gravity; if(pos.top + curr_speed > 95) { temp.css('top', '100px'); } else { temp.css('top', '+='+curr_speed); } } else { var set_opac = drop_y/150; if(set_opac < .2) { set_opac = .2; } temp.animate({ height : curr_speed * 10 + 'px', width : Math.ceil(drop_y*6/100) + 1 + 'px', opacity: set_opac }, 300/curr_speed); setTimeout(function(){ temp.remove(); }, 20000); clearInterval(timer); } }, 10);
}
Rainbow Drops - Script Codes
Rainbow Drops - Script Codes
Home Page Home
Developer Chris Barnes
Username csbarnes
Uploaded August 11, 2022
Rating 4.5
Size 2,365 Kb
Views 46,552
Do you need developer help for Rainbow Drops?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Chris Barnes (csbarnes) Script Codes
Create amazing web content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!