samedi 3 juin 2017

Creating a Div that pops and then disppear in javascript

I am trying to write in javascript a code that shows a div in a random place, then blacks it out after 1000ms and waits for a user's click. My problem is in blackening it (the line that start in //). Could you explain me what's wrong in this?

 <style type="text/css">
    #test {
    position:absolute;
    width:40px;
    height:40px;
    background-color:#d2fcd9;
}

  </style>

  <title></title>

<script type="text/javascript">//<![CDATA[
$(function(){
$('#test').click(function() {
    var docHeight = $(document).height(),
        docWidth = $(document).width(),
        $div = $('#test'),
        divWidth = $div.width(),
        divHeight = $div.height(),
        heightMax = docHeight - divHeight,
        widthMax = docWidth - divWidth;

    $div.css({
        left: Math.floor( Math.random() * widthMax ),
        top: Math.floor( Math.random() * heightMax ),



    });

    //setTimeout(function() {    $div.css({background-color: '#000000'  }); },          300);



});
});//]]> 

</script>

</head>

<body bgcolor="#000000">
  <div id="test" style="left: 1168px; top: 222px;"></div>




Aucun commentaire:

Enregistrer un commentaire