random position of divs in javascript

后端 未结 4 920
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 05:48

I\'m trying to make Divs to appear randomly anywhere on a webpage with javascript. So a div appears then disappears, then another div appears somewhere else on the page then

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 06:39

    Some bugs:

    1. You missed to position the div absolutely. Otherwise it will not work.
    2. I think you need to ad 'px' to the numbers.
    3. The map is made of strings

    Right in your jQuery css setup:

    myDiv.css({
        'position' : 'absolute',
        'top' : finalDivPositionTop + 'px',
        'left' : finalDivPositionLeft + 'px'
    });
    

提交回复
热议问题