想测试一下老师讲的ball.html的动画效果,但是不知道怎么弄?(我是win10系
如下是我的代码
Promise animation .ball{ width: 40px; height: 40px; border-radius: 20px; } .ball1{ background: red; } .ball2{ background: yellow; } .ball3{ background: green; }
var ball1 = document.querySelector('.ball1') var ball2 = document.querySelector('.ball2') var ball3 = document.querySelector('.ball3')function animate(ball,distance,cb){ setTimeout(function(){ var marginLeft = parseInt(ball.style.marginLeft,10) if(marginLeft === distance){ cb && cb() } else{ if(marginLeftnode ball.jsServer running at http://127.0.0.1:8080/D:\imooc\promise\ball.js:15 path.exists(pathname,function(exists){ ^TypeError: path.exists is not a function at Server. (D:\imooc\promise\ball.js:15:7) at emitTwo (events.js:87:13) at Server.emit (events.js:172:7) at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:533:12) at HTTPParser.parserOnHeadersComplete (_http_common.js:103:23)
ball.js 的源码如下
var http = require('http')var url = require('url')var path = require('path')var fs = require('fs')http.createServer(function (req, res) { var pathname=__dirname+url.parse(req.url).pathname; if (path.extname(pathname)=="") { pathname+="/"; } if (pathname.charAt(pathname.length-1)=="/"){ pathname+="index.html"; } path.exists(pathname,function(exists){ if(exists){ switch(path.extname(pathname)){ case ".html": res.writeHead(200, {"Content-Type": "text/html"}); break; case ".js": res.writeHead(200, {"Content-Type": "text/javascript"}); break; case ".css": res.writeHead(200, {"Content-Type": "text/css"}); break; case ".gif": res.writeHead(200, {"Content-Type": "image/gif"}); break; case ".jpg": res.writeHead(200, {"Content-Type": "image/jpeg"}); break; case ".png": res.writeHead(200, {"Content-Type": "image/png"}); break; default: res.writeHead(200, {"Content-Type": "application/octet-stream"}); } fs.readFile(pathname,function (err,data){ res.end(data); }); } else { res.writeHead(404, {"Content-Type": "text/html"}); res.end("404 Not Found
"); } });}).listen(8080, "127.0.0.1");console.log("Server running at http://127.0.0.1:8080/"); |
免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。
版权声明:作者保留权利,不代表天盟立场。
|
|
|
|
你的代码里有几个小错误。。
分别在,31行 ,35行,46行,59行。
<blockquote>
Promise animation
.ball{
width: 40px;
height: 40px;
border-radius: 20px;
}
.ball1{
background: red;
}
.ball2{
background: yellow;
}
.ball3{
background: green;
}
<script type="text/javascript">
var ball1 = document.querySelector('.ball1')
var ball2 = document.querySelector('.ball2')
var ball3 = document.querySelector('.ball3')
function animate(ball,distance,cb){
setTimeout(function(){
var marginLeft = parseInt(ball.style.marginLeft,10)
if(marginLeft === distance){
cb && cb()
}
else{
if(marginLeft |
|
|
|
|