Answer the question
In order to leave comments, you need to log in
Habr's 404 page eats up a lot of CPU resources and the script doesn't turn off?
The script on habrahabr.ru/404/ is written in such a way that it recalculates the coordinates of DOM objects with the maximum speed (1 ms interval) available to the browser. This leads to the fact that loading Firefox on a 2-core e7200, for example, 33%, for Chrome - about 4%, for Opera - 6-8%, is disabled on an inactive tab.
$(document).ready(function(){
var brainstorage = $('.brainstorage')
var hantim = $('.hantim')
var freelansim = $('.freelansim')
var brainstorage_start = 0;
var hantim_start = 1600;
var freelansim_start = 3600;
setInterval(function(){
++brainstorage_start;
var brainstorage_css = {
'left': Math.sin(brainstorage_start * 0.001) * 165,
'top': Math.cos(brainstorage_start * 0.001) * 165
}
brainstorage.css(brainstorage_css);
++hantim_start;
var hantim_css = {
'left': Math.sin(hantim_start * 0.001) * 160 ,
'top': Math.cos(hantim_start * 0.001) * 160
}
hantim.css(hantim_css);
++freelansim_start;
var freelansim_css = {
'left': Math.sin(freelansim_start * 0.001) * 165 ,
'top': Math.cos(freelansim_start * 0.001) * 165
}
freelansim.css(freelansim_css);
}, 1);
})
$('.hantim,.freelansim,.brainstorage').remove();
Answer the question
In order to leave comments, you need to log in
The code on the page was clearly assigned to an inexperienced intern.
- It is necessary to use requestAnimationFrame where it is available
- It is necessary to calculate the position of the object from the time and the equation of motion, and not increase it every time by a certain step (since no one guarantees that the callback will be called evenly, in practice this is not the case)
- Canvas can give a win , or maybe not, plus you have to think about what to do in IE
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question