Refraction image reveal
How do I make an refraction image reveal?
What is a refraction image reveal? How do you make a refraction image reveal? This script and codes were developed by Josh Beckwith on 29 August 2022, Monday.
Refraction image reveal - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Refraction image reveal</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <!-- <div class="refractor" style="width: 1200px; height: 600px;" img-src="http://placekitten.com/1200/630"></div> -->
<!-- <div class="refractor" style="width: 1032px; height: 580px;" img-src="https://coreykoberna.com/wp-content/uploads/2016/07/DS_Branding_MU-uai-1032x580.jpg"></div> -->
<div class="refractor" style="width: 1024px; height: 576px;" img-src="https://www.dropbox.com/s/3iu7qu9zz8g5wgm/xHYMqDXh.jpg?dl=1"></div>
<button>show</button> <script src='https://code.jquery.com/jquery-2.2.4.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.0/TweenMax.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Refraction image reveal - Script Codes CSS Codes
body { background: #111
}
.refractor { position: absolute; top: 50%; left: 50%;
/* transform: translate(-50%, -50%) scale(.5); */ transform: translate(-50%, -50%); background-color: #000;
}
.refractor div { color: red
}
Refraction image reveal - Script Codes JS Codes
var Refractor = function(options){ var boxCountX = options.boxCountX || 14 var boxCountY = options.boxCountY || 7 var offsetStrength = options.offsetStrength || 300 var boxAnimDuration = options.boxAnimDuration === undefined ? 3 : options.boxAnimDuration var $target = options.$target var centerCellX = boxCountX/2 var centerCellY = boxCountY/2 var boxWidth = 100/boxCountX var boxHeight = 100/boxCountY var boxes = [] // strange offset thing that I only sort of understand var txFactor = (100+1/boxCountX*100) var tyFactor = (100+1/boxCountY*100) var initialize = function(){ for (var i = 0; i < boxCountX * boxCountY; i++){ var $box = $('<div>') var left = (i * boxWidth) % 100 var top = Math.floor(i * boxWidth / 100) * boxHeight $box.css({ position: 'absolute', left: left + '%', top: top + '%', width: boxWidth + '%', height: boxHeight + '%', float: 'left', backgroundImage: 'url(' + $target.attr('img-src') + ')', backgroundRepeat: 'no-repeat' }) var cellX = left / 100 * boxCountX var cellY = top / 100 * boxCountY $box.attr({cell: cellX + ',' + cellY}) var tx = (txFactor*cellX/boxCountX) var ty = (tyFactor*cellY/boxCountY) $box.attr({'target-position': tx + '% ' + ty + '%'}) $target.append($box) boxes.push($box) reset() //dev // $box.html($box.attr('cell')) } } var show = function(onComplete){ boxes.forEach(function($box){ TweenMax.to($box, boxAnimDuration, { css: { backgroundPosition: $box.attr('target-position'), opacity: 1 }, ease: Power3.easeOut, }) }) setTimeout(function(){ if(onComplete) onComplete() }, boxes.length * boxAnimDuration) } var reset = function(){ boxes.forEach(function($box, i){ // initial positions // offsets should be determined by vector of cell and center cell var cell = $box.attr('cell').split(',') var xVector = (centerCellX - cell[0]) / boxCountX * offsetStrength + 50 var yVector = (centerCellY - cell[1]) / boxCountY * offsetStrength + 50 // console.log(xVector, yVector) $box.css({ backgroundPosition: xVector + '% ' + yVector + '%', opacity: 0 }) }) } var destroy = function(){ boxes.forEach(function(box){box.remove()}) } var getDistance = function(x1, x2, y1, y2){ return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) } initialize() return { show: show, reset: reset, destroy: destroy }
}
/* example usage PLAY WITH THE NUMBERS!
*/
var r = new Refractor({ $target: $('.refractor'), offsetStrength: 2000, boxAnimDuration: 3, // boxCountX: 1, // boxCountY: 20
})
// demo stuff
setTimeout(function(){ r.show()
}, 1000)
$('button, body').on('click', function(){ r.reset() setTimeout(function(){ r.show() }, 300)
})
Developer | Josh Beckwith |
Username | positlabs |
Uploaded | August 29, 2022 |
Rating | 3 |
Size | 3,014 Kb |
Views | 22,264 |
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!
Name | Size |
Joystick Spinner | 1,788 Kb |
Temporalis | 1,842 Kb |
JitterSCSS | 4,712 Kb |
Time Dilation | 3,166 Kb |
Blurry text | 1,754 Kb |
Hootsuite Button Demo | 1,457 Kb |
Emoji Split | 3,063 Kb |
Youtube iframe player sandbox | 2,171 Kb |
Xtag render | 2,320 Kb |
Cryptaris Glitch Button | 4,648 Kb |
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!
Name | Username | Size |
Basic HTML5 Structure | YuvarajTana | 1,289 Kb |
Minimelephant | Smashlee | 2,507 Kb |
Exploding Text | Jjmartucci | 4,749 Kb |
Content Changer | Cliffpyles | 4,538 Kb |
Wikipedia Viewer | Odylic | 2,333 Kb |
SCSS Simple Animated Drop-In | Danwarfel | 2,175 Kb |
IbrahimJabbari-Effect21 | Ibrahimjabbari | 1,882 Kb |
Arrow Navigation | Hinducows | 1,973 Kb |
Pure CSS Torch Light | Juliendargelos | 2,727 Kb |
DevCamp 2014 - Denver Public Library | See8ch | 5,033 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!