mr_virtus,
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
a {
font: 48px Verdana, Arial, Helvetica, sans-serif;
padding: 5px 15px;
border-radius: 8px;
border: rgb(255, 0, 0) 1px solid;
}
</style>
<script>
window.onload = function() {
function linear(progress) {
return progress;
}
function animate(opts) {
var start = new Date;
var delta = opts.delta || linear;
var timer = setInterval(function() {
var progress = (new Date - start) / opts.duration;
if (progress > 1) progress = 1;
opts.step(delta(progress));
if (progress == 1) {
clearInterval(timer);
opts.complete && opts.complete();
}
}, opts.delay || 13);
return timer;
}
function highlight(elem, delta) {
var from = [102, 51, 255],
to = [255, 255, 51];
animate({
delay: 10,
duration: 5000,
delta: delta,
step: function(delta) {
var r, g, b;
elem.style.backgroundColor = 'rgb(' +
(r = Math.max(Math.min(parseInt((delta * (to[0] - from[0])) + from[0], 10), 255), 0)) + ',' +
(g = Math.max(Math.min(parseInt((delta * (to[1] - from[1])) + from[1], 10), 255), 0)) + ',' +
(b = Math.max(Math.min(parseInt((delta * (to[2] - from[2])) + from[2], 10), 255), 0)) + ')';
elem.style.color = 'rgb(' +
(255 - r) + ',' +
(255 - g) + ',' +
(255 - b) + ')';
}
})
}
[].forEach.call(document.querySelectorAll('a'), function(el) {
el.onclick = function() {
highlight(el, linear);
}
});
};
</script>
</head>
<body> <a>Test click</a>
</body>
</html>
|