3
I’m trying to get a div
is randomly positioned when loading a page.
I thought the following, make the margin-top
and margin-left
of div
were random when loading the page, when clicking again showed another margin, so the div
would have different position. How can I generate random numbers in margin
?
Follows the scope:
<!DOCTYPE html>
<html lang="pt">
<head>
<style type="text/css">
.bloco{
background:blue;
width:100px;
height:100px;
}
</style>
</head>
<body>
<div class="bloco">
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".bloco").css({'margin-top',' ' , 'margin-left', ' '})//<-- colocar aqui margin top e left de forma randomica
//ao carregar pagina
});
</script>
</body>
</html>
Thank you very much for your reply
– blackbird312