Editing User:Toad64/HomepageGive feedback
Jump to navigation
Jump to search
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 1: | Line 1: | ||
<h3> | <h3>Javascript code for herocards</h3> | ||
<p> | <p>Below here is the javascript code that is used for the HeroCards seen on the homepage:</p> | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
document.querySelectorAll('.HeroCard').forEach(function(el) { | document.querySelectorAll('.HeroCard').forEach(function(el) { | ||
| Line 12: | Line 12: | ||
var mouseX = 0, mouseY = 0; | var mouseX = 0, mouseY = 0; | ||
var isOver = false; | var isOver = false; | ||
document.addEventListener('mousemove', function(e) { | |||
mouseX = e.clientX; | |||
mouseY = e.clientY; | mouseY = e.clientY; | ||
} | }); | ||
var tick = function() { | var tick = function() { | ||
var | var rect = el.getBoundingClientRect(); | ||
isOver = ( | |||
mouseX >= rect.left && | |||
mouseX <= rect.right && | |||
mouseY >= rect.top && | |||
mouseY <= rect.bottom | |||
); | |||
target.x = dy * -12; | if (isOver) { | ||
var cx = rect.left + rect.width / 2; | |||
var cy = rect.top + rect.height / 2; | |||
var dx = (mouseX - cx) / (rect.width / 2); | |||
var dy = (mouseY - cy) / (rect.height / 2); | |||
target.x = dy * -12; | |||
target.y = dx * 12; | |||
} else { | |||
target.x = 0; | |||
target.y = 0; | |||
} | |||
current.x += (target.x - current.x) * 0.12; | current.x += (target.x - current.x) * 0.12; | ||
| Line 33: | Line 44: | ||
el.style.transform = 'perspective(400px) rotateX(' + current.x + 'deg) rotateY(' + current.y + 'deg) scale(' + (isOver ? 1.05 : 1) + ')'; | el.style.transform = 'perspective(400px) rotateX(' + current.x + 'deg) rotateY(' + current.y + 'deg) scale(' + (isOver ? 1.05 : 1) + ')'; | ||
requestAnimationFrame(tick); | |||
}; | }; | ||
tick(); | |||
}); | }); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<p> You can see this code in action by clicking [https://deadlock.wiki/wiki/User:Toad64/Sandbox?withJS=User:Toad64/common.js Here].</p> | |||
<p> You can see | |||
{{Deadlock Wiki/Heroes}} | {{Deadlock Wiki/Heroes}} | ||