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

编程入门 行业动态 更新时间:2024-10-26 04:24:40
本文介绍了jsFiddle代码在本地计算机上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使元素在<div>

非常感谢,有人找到了一个解决方案,可以在此处

Thankfully, someone has found a solution which can be found here

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

However, when I run it on my local machine OR on a server, the element does not move.

这是我的源代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="www.w3/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/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]; } function animateDiv(){ var newq = makeNewPosition(); var oldq = $('.a').offset(); var speed = calcSpeed([oldq.top, oldq.left], newq); $('.a').animate({ top: newq[0], left: newq[1] }, speed, function(){ animateDiv(); }); }; function calcSpeed(prev, next) { var x = Math.abs(prev[1] - next[1]); var y = Math.abs(prev[0] - next[0]); var greatest = x > y ? x : y; var speedModifier = 0.1; var speed = Math.ceil(greatest/speedModifier); return speed; }​ </script> </head> <body> <div class='a'></div>​ </body> </html>

推荐答案

在Chrome中打开时,出现错误:

Opening in Chrome, I got an error:

Uncaught SyntaxError: Unexpected token ?

在javascript中,大括号后面似乎有一个不可见的字符.用记事本++打开并删除多余的字符.

It looks like there is a non-visible character after the ending brace in the javascript. Open with Notepad++ and delete the extra character.

当您直接从小提琴复制并粘贴时,我已经看到这种情况发生.

I have seen this happen when you copy and paste directly from a fiddle.

更多推荐

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

本文发布于:2023-11-01 17:39:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549976.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上不   代码   计算机   jsFiddle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!