Punch Button

Developer
Size
3,958 Kb
Views
24,288

How do I make an punch button?

A button that has text punched out of it.. What is a punch button? How do you make a punch button? This script and codes were developed by Josh Beckwith on 29 August 2022, Monday.

Punch Button Previews

Punch Button - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Punch Button</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src="https://rawgit.com/x-tag/core/master/dist/x-tag-core.js"></script>
<iframe class="video" src="https://player.vimeo.com/video/104094320?autoplay=1&loop=1&color=ff9933&title=0&byline=0&portrait=0" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<punch-button label="PUNCH BUTTON"></punch-button> <script src="js/index.js"></script>
</body>
</html>

Punch Button - Script Codes CSS Codes

punch-button { position: relative; font-weight: bold; text-align: center; letter-spacing: .2em; font-size: 1.5em; border-radius: 3px; overflow: hidden; white-space: nowrap;
}
punch-button div { border: 1px solid red; padding: 20px 35px;
}
punch-button canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%;
}
punch-button { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
}
body { background: black; color: white; font-family: Helvetica, Arial, sans-serif; margin: 0; padding: 0; position: absolute; top: 0; left: 0; width: 100%; height: 100%;
}
.video { position: absolute; width: 100%; height: 100%;
}

Punch Button - Script Codes JS Codes

'use strict';
/* credits: grabbed some code from this gist https://gist.github.com/psobot/4311375 video by beeple: http://beeple-crap.com/
*/
xtag.register('punch-button', { content: '\n <div></div>\n <canvas>\n ', lifecycle: { created: function created() { this._canvas = this.querySelector('canvas'); this._ctx = this._canvas.getContext('2d'); this._div = this.querySelector('div'); this._div.style.opacity = 0; // this._canvas.style.opacity = 0 } }, accessors: { label: { attribute: {}, get: function get() { return this._label; }, set: function set(label) { this._label = label; this._div.innerHTML = label; this.draw(); } } }, methods: { draw: function draw() { var style = document.defaultView.getComputedStyle(this, ""); var dpr = window.devicePixelRatio || 1; this._canvas.width = this.offsetWidth * dpr; this._canvas.height = this.offsetHeight * dpr; this._ctx.fillStyle = '#ffffff'; this._ctx.fillRect(0, 0, this._canvas.width, this._canvas.height); this._ctx.fillStyle = '#000000'; var fontSplit = style.font.split(' '); fontSplit[4] = parseInt(fontSplit[4]) * dpr + 'px'; // dpr font size this._ctx.font = fontSplit.join(' '); this._ctx.textBaseline = 'top'; this._ctx.globalCompositeOperation = 'destination-out'; var textWidth = this._ctx.measureText(this._label, 0, 0).width; var left = (this._canvas.width - textWidth) * .5; var textHeight = this._ctx.measureText('M').width; var top = (this._canvas.height - textHeight) * .5; this._ctx.fillText(this._label, left, top); } }
});
Punch Button - Script Codes
Punch Button - Script Codes
Home Page Home
Developer Josh Beckwith
Username positlabs
Uploaded August 29, 2022
Rating 3
Size 3,958 Kb
Views 24,288
Do you need developer help for Punch Button?

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!

Josh Beckwith (positlabs) Script Codes
Create amazing Facebook ads 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!