I'm trying to make a div
randomly position when loading page.
I thought of the following, to make the margin-top
and margin-left
of div
were random when loading the page, when loading again already displayed another margin, so div
would have different position. How can I do to generate random numbers in margin
?
The scope follows:
<!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>