它不会解决你的问题,但这里有一些事情可以改进你的 js:
$(".postIt-" + id).css("width",wh);
$(".postIt-" + id).css("height",wh);
$(".postIt-" + id).css("transform","rotate("+rotatedegree+"deg)");
// ...
不要重复$(".postIt-" + id),它更慢而且没用:
$(".postIt-" + id).css("width",wh)
.css("height",wh)
.css("transform","rotate("+rotatedegree+"deg)")
// ...
而不是这个:
if (randomBg == 1){
$(".postIt-" + id).addClass("bg_one");
}
if (randomBg == 2){
$(".postIt-" + id).addClass("bg_two");
}
做这个:
var setRandomBg = function(postit_id, bg_id) {
$(".postIt-" + postit_id).addClass("bg_" + bg_id); // you would need to rename your classes with numbers
}
// and call it
setRandomBg(id, randomBg);