Responsive Codepen Glitch

Developer
Size
2,838 Kb
Views
48,576

How do I make an responsive codepen glitch?

Minimal responsive glitch effect with the codepen logo.. What is a responsive codepen glitch? How do you make a responsive codepen glitch? This script and codes were developed by Moklick on 20 November 2022, Sunday.

Responsive Codepen Glitch Previews

Responsive Codepen Glitch - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Responsive Codepen Glitch</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas id="canvas"></canvas> <script src="js/index.js"></script>
</body>
</html>

Responsive Codepen Glitch - Script Codes CSS Codes

*{ margin: 0; padding: 0;
}
body { background: black;
}
canvas { margin: 20px auto; display: block;
}

Responsive Codepen Glitch - Script Codes JS Codes

'use strict';
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var img = new Image();
var w = undefined;
var h = undefined;
var glitchInterval = undefined;
var offset = undefined;
var init = function init() {	clearInterval(glitchInterval);	canvas.width = w = window.innerWidth;	offset = w * .1;	canvas.height = h = ~ ~(650 * ((w - offset * 2) / img.width));	glitchInterval = setInterval(function () {	clear();	context.drawImage(img, 0, 0, img.width, 750, offset, 0, w - offset * 2, h);	setTimeout(glitchImg, randInt(250, 1000));	}, 500);
};
var clear = function clear() {	context.rect(0, 0, w, h);	context.fill();
};
var glitchImg = function glitchImg() {	for (var i = 0; i < randInt(1, 13); i++) {	var x = Math.random() * w;	var y = Math.random() * h;	var spliceWidth = w - x;	var spliceHeight = randInt(5, h / 3);	context.drawImage(canvas, 0, y, spliceWidth, spliceHeight, x, y, spliceWidth, spliceHeight);	context.drawImage(canvas, spliceWidth, y, x, spliceHeight, 0, y, x, spliceHeight);	}
};
var randInt = function randInt(a, b) {	return ~ ~(Math.random() * (b - a) + a);
};
img.onload = function () {	init();	window.onresize = init;
};
img.src = 'https://production-assets.codepen.io/assets/logos/codepen-logo-0b07553e128f9be6a5f2e8a3f80a08f2772c2f56c054d78091ee82f6f3f02727.svg';
Responsive Codepen Glitch - Script Codes
Responsive Codepen Glitch - Script Codes
Home Page Home
Developer Moklick
Username moklick
Uploaded November 20, 2022
Rating 4.5
Size 2,838 Kb
Views 48,576
Do you need developer help for Responsive Codepen Glitch?

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!

Moklick (moklick) Script Codes
Create amazing love letters 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!