Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 随机旋转html元素_Javascript_Random_Rotation_Position - Fatal编程技术网

Javascript 随机旋转html元素

Javascript 随机旋转html元素,javascript,random,rotation,position,Javascript,Random,Rotation,Position,我想在屏幕上随机旋转(绝对放置)一堆列表项,发现这只能通过javascript实现,而不是我第一次尝试的css3 我在中找到了一个很好的解决方案,但它只有在悬停时才会旋转。因为我不是javascript专家,所以我无法在加载时而不是在悬停时这样做 在那之后,我会找到一种方法来随机输入顶部和左侧的值,但是如果你已经有了这个解决方案,我很乐意听到它 感谢您的时间:)根据引用的漂亮解决方案,您可以重用它,但在加载页面时调用它,如下所示: // this will be called onload jQ

我想在屏幕上随机旋转(绝对放置)一堆列表项,发现这只能通过javascript实现,而不是我第一次尝试的css3

我在中找到了一个很好的解决方案,但它只有在悬停时才会旋转。因为我不是javascript专家,所以我无法在加载时而不是在悬停时这样做

在那之后,我会找到一种方法来随机输入顶部和左侧的值,但是如果你已经有了这个解决方案,我很乐意听到它

感谢您的时间:)

根据引用的漂亮解决方案,您可以重用它,但在加载页面时调用它,如下所示:

// this will be called onload
jQuery(function($) {
    // changed .hover to .each
    $('.photo').each(function() {
        var a = Math.random() * 10 - 5;
        $(this).css('transform', 'rotate(' + a + 'deg)');
    });
});
根据引用的漂亮解决方案,您可以重用它,但在加载页面时调用它,如下所示:

// this will be called onload
jQuery(function($) {
    // changed .hover to .each
    $('.photo').each(function() {
        var a = Math.random() * 10 - 5;
        $(this).css('transform', 'rotate(' + a + 'deg)');
    });
});

到底为什么要设置间隔?我以为他想不断地给它设置动画。现在编辑。到底为什么设置间隔?我以为他想连续地给它设置动画。现在编辑。非常感谢Shanon!这对我来说似乎是对的,但我没能做到。我已经更新了你的代码笔并调整了JS。现在,它在Chrome中为我工作:非常感谢Shanon!这对我来说似乎是对的,但我没能做到。我已经更新了你的代码笔并调整了JS。现在,它在Chrome中为我工作: