我有以下代码:
$(document).ready(function() {
$(".content-image").each(function() {
var angle = randAngle();
$(".content-image").css("transform", "rotate(" + angle + "deg)");
});
});
function randAngle() {
return Math.floor(Math.random() * 5) + 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img class="content-image" src="https://via.placeholder.com/150" />
<img class="content-image" src="https://via.placeholder.com/150" />
但是它以相同的 Angular 旋转所有图像。如何为每张图片设置不同的 Angular ?
最佳答案
改变
$(".content-image").css("transform"...
到
$(this).css("transform"...
以便它一次将变换应用于循环中的每个图像
关于jquery - 如何旋转多张图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54595998/