Skip to content

Instantly share code, notes, and snippets.

View worldoptimizer's full-sized avatar
💭
Homeoffice

Max Ziebell worldoptimizer

💭
Homeoffice
View GitHub Profile
/**
* Converts a key and value to a string.
*
* @param {strin} key
* @param {string|number|boolean|object|function} value
* @param {string} indent
* @return {string}
*/
function keyToString(key, value, indent) {
/**
* Resolve variables in string using a variable lookup
*
* @param {string} str The string to resolve variables in.
* @param {object} variables The variables to resolve.
* @returns {string} The resolved string.
*/
function resolveVariablesInString(str, variables) {
if (typeof str === 'string') {
var matches = str.match(/\${.*?}|%{.*?}|✨{.*?}/g);
setInterval(function(){
var elm = document.querySelector((Math.random()>0.5)? '#leftKey' : '#rightKey');
elm.click();
}, 100);
anime({
targets: '.circle',
translateX: '250px',
translateY: '150px',
backgroundColor: '#FFF',
rotateY: '360deg',
rotateX: '360deg',
easing: 'easeInOutQuad',
changeComplete: function(anim){
@worldoptimizer
worldoptimizer / hypeDocument.syncHypeToAnime.js
Created September 18, 2020 19:51
Sync values animated in Anime.js to Hype
hypeDocument.syncHypeToAnime = function(anim){
var reverselookup = {'translateX': 'left', 'translateY': 'top'}
anim.animations.forEach(function(a){
if (!a.animatable.target.classList.contains('HYPE_element')) return;
if (['top','left','translateX', 'translateY', 'width','height','rotateZ','scaleX','scaleY','opacity','z-index'].includes(a.property)){
var hypeProp = reverselookup[a.property] || a.property;
hypeDocument.setElementProperty(a.animatable.target, hypeProp, parseFloat(a.currentValue) );
}
});
}
@worldoptimizer
worldoptimizer / pauseIfPlayingForward.js
Created September 15, 2020 15:10
If you need to create a directional pause this little timeline action should be helpful.
if ( hypeDocument.currentDirectionForTimelineNamed(event.timelineName) == hypeDocument.kDirectionForward) {
hypeDocument.pauseTimelineNamed(event.timelineName);
}
@worldoptimizer
worldoptimizer / hypeDocument.disablePhysicsCollisions.js
Created September 12, 2020 12:59
hypeDocument.disablePhysicsCollisions
/**
* Remove phyics elements from the regular Matter.js collision group
*
* @param {Nodelist} targetElms The target elements to remove
*/
hypeDocument.disablePhysicsCollisions = function(targetElms) {
targetElms.forEach(function(elm){
var elmBody = hypeDocument.getElementProperty(elm, 'physics-body');
if (elmBody) elmBody.collisionFilter = { 'group': -1}
});
@worldoptimizer
worldoptimizer / hypeDocument.queryIntersections.js
Created September 12, 2020 12:55
hypeDocument.queryIntersections
/**
* Query intersections between elements using Matter.js
*
* @param {Node} sourceElm The source element used in each check
* @param {Nodelist} targetElms The target elements to query against
* @return {Nodelist} Returns a list of targetElms that intersect with sourceElm
*/
hypeDocument.queryIntersections = function(sourceElm, targetElms) {
var sourceBody = hypeDocument.getElementProperty(sourceElm, 'physics-body');
if (sourceBody) {
@worldoptimizer
worldoptimizer / spine.css
Created May 10, 2020 09:30
Book Spin in CSS
.Product-book .book-section .book-cover .cover-spine-overlay img{
width:100%;
display:block;
-webkit-box-shadow:0 0 16px rgba(0,0,0,0.5);
box-shadow:0 0 16px rgba(0,0,0,0.5)
}
.Product-book .book-section .book-cover .cover-spine-overlay:after{
position:absolute;
content:"";
width:100%;
function symbolInitTest (hypeDocument, element, event){
console.log('HypeSymbolInit');
var symbolInstance = hypeDocument.getSymbolInstanceForElement(element);
// do your stuff…
}
window.HYPE_eventListeners.push({"type":"HypeSymbolInit", "callback":symbolInitTest});