CSS optical illusion

Size
3,443 Kb
Views
99,176

How do I make an css optical illusion?

Booth blocks have the same speed and position at all times.Click toggle to change the background and see for yourself.. What is a css optical illusion? How do you make a css optical illusion? This script and codes were developed by Ludvig Lindblom on 25 July 2022, Monday.

CSS optical illusion Previews

CSS optical illusion - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>CSS optical illusion</title> <script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ html { background: #999; padding: 0;
}
body { margin: 0; padding: 0;
}
a { font-family: sans-serif; font-size: 20px; font-weight: bold; line-height: 1; text-decoration: none; display: inline-block; padding: 10px; background: #000; color: #fff;
}
a:hover, a:focus { text-decoration: underline;
}
#track { background-color: #999; background-image: linear-gradient(90deg, #000 0%, #000 50%, #fff 50%, #fff 100%); background-size: 50px 50px; border: 1px solid #000; width: 675px; height: 225px; position: absolute; top: 0; right: 0; bottom: 0; left: 0; margin: auto; padding: 0;
}
#track.proof { background-image: none;
}
.block { width: 100px; height: 40px; position: absolute; left: 0; animation: illusion 9s linear infinite alternate;
}
.block.light { background: #fff; top: 10px;
}
.block.dark { background: #000; bottom: 10px;
}
@keyframes illusion { from { left: 0; } to { left: calc(100% - 100px); }
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <a href='#'>Toggle</a>
<div id='track'> <div class='block light'></div> <div class='block dark'></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>

CSS optical illusion - Script Codes CSS Codes

html { background: #999; padding: 0;
}
body { margin: 0; padding: 0;
}
a { font-family: sans-serif; font-size: 20px; font-weight: bold; line-height: 1; text-decoration: none; display: inline-block; padding: 10px; background: #000; color: #fff;
}
a:hover, a:focus { text-decoration: underline;
}
#track { background-color: #999; background-image: linear-gradient(90deg, #000 0%, #000 50%, #fff 50%, #fff 100%); background-size: 50px 50px; border: 1px solid #000; width: 675px; height: 225px; position: absolute; top: 0; right: 0; bottom: 0; left: 0; margin: auto; padding: 0;
}
#track.proof { background-image: none;
}
.block { width: 100px; height: 40px; position: absolute; left: 0; animation: illusion 9s linear infinite alternate;
}
.block.light { background: #fff; top: 10px;
}
.block.dark { background: #000; bottom: 10px;
}
@keyframes illusion { from { left: 0; } to { left: calc(100% - 100px); }
}

CSS optical illusion - Script Codes JS Codes

$("body").on("click", "a", function(e) { e.preventDefault(); $("#track").toggleClass("proof");
});
CSS optical illusion - Script Codes
CSS optical illusion - Script Codes
Home Page Home
Developer Ludvig Lindblom
Username ludviglindblom
Uploaded July 25, 2022
Rating 4
Size 3,443 Kb
Views 99,176
Do you need developer help for CSS optical illusion?

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!

Ludvig Lindblom (ludviglindblom) Script Codes
Create amazing marketing copy 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!