小编Ste*_*tin的帖子

jsFiddle代码在本地计算机上不起作用

我正在尝试使元素在内部随机移动 <div>

幸运的是,有人找到了一个解决方案,可以在这里找到

但是,当我在本地计算机或服务器上运行该元素时,该元素不会移动。

这是我的源代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>

<style type="text/css">
div.a {
    width: 50px;
    height:50px;
    background-color:red;
    position:fixed;    
}?
</style>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
    animateDiv();

});

function makeNewPosition(){

    // Get viewport dimensions (remove the dimension of the div)
    var h = $(window).height() - 50;
    var w = $(window).width() - 50;

    var nh = Math.floor(Math.random() * h);
    var nw = Math.floor(Math.random() * w);

    return [nh,nw]; …
Run Code Online (Sandbox Code Playgroud)

jquery jsfiddle

2
推荐指数
1
解决办法
617
查看次数

标签 统计

jquery ×1

jsfiddle ×1