I'm testing an effect where pixels follow your mouse. http://dukevin.com/pixel
But my current implementation is very resource heavy; create divs that fill the page and query them to change the color.
Is there a way that can produce a similar effect without being so resource heavy? An idea I have is to generate the divs on the fly as the mouse moves, and remove them when faded out.
$(document).ready(function(){
var body = $('body');
for(var i = 0; i < Math.floor($(window).width()/30)*Math.floor($(window).height()/30) ; i++)
body.append("<div class=box></div>");
});
var colors = ["#f00","#c00","#d00","#e00"];
$(document).on('mouseenter', '.box', function (event) {
$(this).css({
backgroundColor: colors[Math.floor(Math.random() * colors.length)],
opacity: 1
});
}).on('mouseleave', '.box', function (event) {
$(this).css('opacity', 0);
});
body {
width: 100%;
margin: 0;
padding: 0;
line-height: 0px;
background-color: #333;
}
.box {
display: inline-block;
vertical-align:top;
z-index: -1;
width: 30px;
height: 30px;
transition: all 2s ease;
}
.box:hover {
transition: all 0s ease;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>