Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =====================================================
- === paste the following immediately after <style> ===
- =====================================================
- #snail-container {
- bottom:0;
- width:100%;
- position:fixed;
- pointer-events:none;
- }
- .snail {
- display:none;
- z-index:100;
- pointer-events:auto;
- position:absolute;
- bottom:0;
- }
- ===============================================
- === paste the rest immediately after <body> ===
- ===============================================
- <div id="snail-container">
- <img src="https://i.imgur.com/hBqxGXP.gif" class="snail" id="snailidle" title="click me! double click to send me away! code by pyrlspite"/>
- <img src="https://i.imgur.com/oid5qEH.gif" class="snail" id="snailmove" title="click me! double click to send me away! code by pyrlspite"/>
- <img src="https://i.imgur.com/XExyMFf.png" id="snailheart" style="display:none; position:absolute; z-index:101; bottom:0; left:0; pointer-events:none;"/>
- </div>
- <!-- snail script by pyrlspite.tumblr.com -->
- <script>
- var currentsnail = "snailidle", snaildir = "right", snailpos = 0, snailcounter = 0, heartcounter = 0, heartpos = 0, snailtimer = setInterval(snailstep, 15);
- var snailmoveid = document.getElementById("snailmove");
- var snailidleid = document.getElementById("snailidle");
- var snailheartid = document.getElementById("snailheart");
- function showsnail(snail) {
- document.getElementById(currentsnail).style.display = "none";
- document.getElementById(snail).style.display = "block";
- currentsnail = snail;
- }
- function flipsnail(dir) {
- if(dir == "right"){
- snailmoveid.style.transform = "scaleX(1)";
- snailidleid.style.transform = "scaleX(1)";
- snaildir = "right";
- } else if(dir == "left"){
- snailmoveid.style.transform = "scaleX(-1)";
- snailidleid.style.transform = "scaleX(-1)";
- snaildir = "left";
- }
- }
- snailmoveid.onclick = function() {placeheart()};
- snailidleid.onclick = function() {placeheart()};
- snailmoveid.ondblclick = function() {goodbye()};
- snailmoveid.ondblclick = function() {goodbye()};
- function placeheart() {
- heartcounter = Math.floor((Math.random() * 25) + 10);
- heartpos = Math.floor((Math.random() * 20) + 2);
- snailheartid.style.left = (snailpos + Math.floor((Math.random() * 30) - 10)) + 'px';
- snailheartid.style.bottom = heartpos + 'px';
- snailheartid.style.display = "block";
- }
- function gensnaildir() {
- if(Math.random() >= 0.5) {
- return "left";
- } else {
- return "right";
- }
- }
- function gensnailidle() {
- if(Math.random() >= 0.5) {
- return "snailidle";
- } else {
- return "snailmove";
- }
- }
- function snailstep() {
- if(snailcounter == 0) {
- snailcounter = Math.floor((Math.random() * 100) + 10);
- flipsnail(gensnaildir());
- showsnail(gensnailidle());
- }
- if(snailpos <= 0) {
- flipsnail("right");
- }
- if(snailpos >= (document.getElementById("snail-container").offsetWidth - document.getElementById(currentsnail).offsetWidth)) {
- flipsnail("left");
- }
- if(currentsnail == "snailidle") {
- snailcounter--;
- } else {
- if(snaildir == "left") {
- snailpos--;
- } else {
- snailpos++;
- }
- snailidleid.style.left = snailpos + 'px';
- snailmoveid.style.left = snailpos + 'px';
- snailcounter--;
- }
- heartpos++;
- snailheartid.style.bottom = heartpos + 'px';
- heartcounter--;
- if(heartcounter <= 0) {
- snailheartid.style.display = "none";
- }
- }
- function goodbye() {
- clearInterval(snailtimer);
- if(currentsnail == snailidle) {
- showsnail(snailmove);
- }
- if(snaildir == "left") {
- flipsnail("right");
- }
- snailtimer = setInterval(snailGoodbye, 5);
- }
- function snailGoodbye() {
- snailpos++;
- snailmoveid.style.left = snailpos + 'px';
- heartpos++;
- snailheartid.style.bottom = heartpos + 'px';
- heartcounter--;
- if(heartcounter <= 0) {
- snailheartid.style.display = "none";
- }
- if(snailpos >= (document.getElementById("snail-container").offsetWidth)) {
- clearInterval(snailGoodbye);
- }
- }
- </script>
Add Comment
Please, Sign In to add comment