听说今天是七夕,那我们写一个网页开发来庆祝一下!!

文章目录

  • 听说今天是七夕,那我们写一个网页开发来庆祝一下!!
    • 一、情况介绍
    • 二、项目介绍
    • 三、项目的代码实现
    • 四、项目的核心代码
    • 五、项目展示
    • 六、总结

一、情况介绍

今天是七夕佳节,是中国传统的情人节,

逢此佳节,博主也来写一个网页开发来庆祝一下七夕,

虽然博主是下图的情况:

但是,

正是处于这种情况,

才会有闲心来搞一些事情了啦~~

二、项目介绍

本项目中,我们使用了 Node 的 Express 框架,以此作为服务器后端,然后在前段,我们使用模板进行代码的编写,这样可以省去很多不必要的代码了啦。

然后,最终的成果是一个前端再加一个服务器,这里我们没有使用 Git, 只不过使用他来做了一个记录,没有远程仓库。

三、项目的代码实现

在项目的index.js 中:
(这个是实现Node服务器)

let express = require("express")
let app = express()let formidable = require("formidable")
let handlebars = require("express3-handlebars").create({defaultLayout: "main"})app.use(require("body-parser")())app.use(express.static(__dirname + "/public"))app.engine("handlebars", handlebars.engine)
app.set("view engine", "handlebars")
app.set("port", process.env.PORT || 3000)app.get("/end", (req, res)=>{res.render("end")
})// app.get("/thirteenth", (req, res)=>{// res.render("thirteenth")
// })app.get("/thirteenth", (req, res)=>{res.render("thirteenth")
})app.get("/twelfth", (req, res)=>{res.render("twelfth")
})app.get("/eleventh", (req, res)=>{res.render("eleventh")
})app.get("/tenth", (req, res)=>{res.render("tenth")
})app.get("/nineth", (req, res)=>{res.render("nineth")
})app.get("/eighth", (req, res)=>{res.render("eighth")
})app.get("/seventh", (req, res)=>{res.render("seventh")
})app.get("/sixth", (req, res)=>{res.render("sixth")
})app.get("/fifth", (req, res)=>{res.render("fifth")
})app.get("/forth", (req, res)=>{res.render("forth")
})app.get("/third", (req, res)=>{res.render("third")
})app.get("/second", (req, res)=>{res.render("second")
})app.get("/first", (req, res)=>{res.render("first")
})// get / -> home
// app.get("/", (req, res)=>{//     res.render("home")
// })app.get("/", (req, res)=>{res.render("home")
})app.use((req, res)=>{res.status(404)res.render("404")
})app.use((err, req, res, next)=>{console.log(err.static)res.static(500)res.render("500")
})app.listen(app.get("port"), ()=>{console.log("Express start on http://localhost:" + app.get("port") + ";press Ctrl - C to terminate......")
})

而在 模板 main.handlebrs 中:
(这是一个主模板)

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><title>The Qi Xi Festival</title><style type="text/css">/*basic reset*/*{margin:0;padding:0;}body{background:rgb(250, 246, 246);}canvas{display:block;}</style></head><body>{{{body}}}</body>
</html>{{!-- <style type="text/css">
/*basic reset*/
*{margin:0;padding:0;}
body{background:black;}
canvas{display:block;}
</style> --}}

至于在 home.handlebars 中:
(这是主页)

<a href="http://localhost:3000/first/"><div style="position: relative;"><span style="position: absolute;font-size:xx-large;color:honeydew;">Qi Xi (click the window to go on)</span><img src="/pictures/qixi01.jpg" style=""></div>
</a>

然后,在 后面的一些模板文件中也是类似的,我们此处只展示另外一个模板文件,first.handlebars 中:
(这是第一个图像)

<a href="http://localhost:3000/second/"><div style="position: relative;"><span style="position: absolute;font-size:xx-large;color:violet;line-height: 1000px;vertical-align: middle;">&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;The wind blows in the evening of July</span><img src="/pictures/qixi09.png" style=""></div>
</a>

最后,还有最后一个 end.handlebars 中:
(这是最后一个图像)

<canvas id="c"></canvas>
<script type="text/javascript">
var c=document.getElementById("c")
var ctx= c.getContext("2d")
c.height=window.innerHeight
c.width=window.innerWidth
var chinese="❤LOVE❤"
chinese=chinese.split("")
var font_size=22
var columns=c.width/font_size
var drops=[]
for(var x=0;x<columns;x++)drops[x]=1
function draw(){ctx.fillStyle="rgba(0, 0, 0, 0.05)"ctx.fillRect(0,0,c.width,c.height)ctx.fillStyle="#0F0"ctx.font=font_size+"px arial"for(var i=0;i<drops.length;i++){var text=chinese[Math.floor
(Math.random()*chinese.length)]
ctx.fillText(text,i*font_size,drops[i]*font_size)
if(drops[i]*font_size>c.height&&Math.random()>0.975)drops[i]=0drops[i]++}
}
setInterval(draw,50)
</script>
<audio autoplay="autoplay" loop="loop" preload="auto"src="/media/mp3/Two Steps From Hell&Thomas Bergersen-Star Sky.mp3">Can not play the media!
</audio>

整个项目的 JSON 文件为:

{"name": "qi_xi","version": "1.0.0","description": "qi xi festival","main": "index.js","scripts": {"test": "node index.js"},"repository": {"type": "git","url": "now is none"},"keywords": ["671513"],"author": "hu yu xuan","license": "ISC"
}

以上就是我们的整个项目的一些代码。

四、项目的核心代码

本项目最核心的代码是服务器的构建,以及最后一个图像的绘制:

服务器:

let express = require("express")
let app = express()let formidable = require("formidable")
let handlebars = require("express3-handlebars").create({defaultLayout: "main"})app.use(require("body-parser")())app.use(express.static(__dirname + "/public"))app.engine("handlebars", handlebars.engine)
app.set("view engine", "handlebars")
app.set("port", process.env.PORT || 3000)app.get("/end", (req, res)=>{res.render("end")
})// app.get("/thirteenth", (req, res)=>{// res.render("thirteenth")
// })app.get("/thirteenth", (req, res)=>{res.render("thirteenth")
})app.get("/twelfth", (req, res)=>{res.render("twelfth")
})app.get("/eleventh", (req, res)=>{res.render("eleventh")
})app.get("/tenth", (req, res)=>{res.render("tenth")
})app.get("/nineth", (req, res)=>{res.render("nineth")
})app.get("/eighth", (req, res)=>{res.render("eighth")
})app.get("/seventh", (req, res)=>{res.render("seventh")
})app.get("/sixth", (req, res)=>{res.render("sixth")
})app.get("/fifth", (req, res)=>{res.render("fifth")
})app.get("/forth", (req, res)=>{res.render("forth")
})app.get("/third", (req, res)=>{res.render("third")
})app.get("/second", (req, res)=>{res.render("second")
})app.get("/first", (req, res)=>{res.render("first")
})// get / -> home
// app.get("/", (req, res)=>{//     res.render("home")
// })app.get("/", (req, res)=>{res.render("home")
})app.use((req, res)=>{res.status(404)res.render("404")
})app.use((err, req, res, next)=>{console.log(err.static)res.static(500)res.render("500")
})app.listen(app.get("port"), ()=>{console.log("Express start on http://localhost:" + app.get("port") + ";press Ctrl - C to terminate......")
})

最后一个图像的绘制

<canvas id="c"></canvas>
<script type="text/javascript">
var c=document.getElementById("c")
var ctx= c.getContext("2d")
c.height=window.innerHeight
c.width=window.innerWidth
var chinese="❤LOVE❤"
chinese=chinese.split("")
var font_size=22
var columns=c.width/font_size
var drops=[]
for(var x=0;x<columns;x++)drops[x]=1
function draw(){ctx.fillStyle="rgba(0, 0, 0, 0.05)"ctx.fillRect(0,0,c.width,c.height)ctx.fillStyle="#0F0"ctx.font=font_size+"px arial"for(var i=0;i<drops.length;i++){var text=chinese[Math.floor
(Math.random()*chinese.length)]
ctx.fillText(text,i*font_size,drops[i]*font_size)
if(drops[i]*font_size>c.height&&Math.random()>0.975)drops[i]=0drops[i]++}
}
setInterval(draw,50)
</script>
<audio autoplay="autoplay" loop="loop" preload="auto"src="/media/mp3/Two Steps From Hell&Thomas Bergersen-Star Sky.mp3">Can not play the media!
</audio>

五、项目展示

主页如下:


(点击屏幕会继续向后进行继续)

其他的页面:


1


2


3


4


5


6

结尾的页面:

这个四无限的屏幕刷屏显示, 同时还配有音乐,我配的是Star Sky


六、总结

如果需要源代码的话,可以在我的资源哪里进行下载了啦:
https://download.csdn.net/download/m0_54218263/21071555?spm=1001.2014.3001.5503

啊,虽然博主做了一个七夕的小项目,但是呢,又没有人可以送,于是就在这里进行分享了啦。

曾经,博主还在一直思考,为什么博主这么菜,什么都不会,也没有npy,后来。。。。。。

同时,常常记得另一个博主的TCP讲解:


。。。。。


最后,谢谢大家的阅读了

谢谢支持!!

(づ ̄3 ̄)づ╭❤~

喜欢的话就留下来点个赞呗~~

听说今天是七夕,那我们写一个网页开发来庆祝一下相关推荐

  1. 网页 php,怎么用php写一个网页

    怎么用php写一个网页 在web服务器根目录下建立一个文件名为index.php的文件,然后完成如下内容: 第一个php网页 <?php echo ' Hello World '; ?> ...

  2. [JSP] 利用application来写一个网页计数器

    利用application写一个网页计数器 实现这一应用, 要用到application下面的两个方法: application.setAttribute() 和 application.getAtt ...

  3. 帮我写一个网页扫雷游戏基本的版本

    好的,我来帮你写一个基本版本的网页扫雷游戏. 首先,你需要熟悉 HTML.CSS 和 JavaScript 等前端技术,并了解二维数组.循环.判断语句等编程基础知识. 以下是简单的代码实现: HTML ...

  4. CSS代码写一个网页,有留言板

    可以这样写 CSS 代码来创建一个留言板: /* 定义留言板的外观 */ .message-board {width: 500px;height: 400px;background-color: #f ...

  5. 用原生JS写一个网页版的2048小游戏(兼容移动端)

    这个游戏JS部分全都是用原生JS代码写的,加有少量的CSS3动画,并简单的兼容了一下移动端. 先看一下在线的demo:https://yuan-yiming.github.io/2048-online ...

  6. 我自己动手写一个网页收藏站,你说行不行?【html+css+js】#谭子

    摘要:我的博客必须得浅显易懂,还得具有实践操作的可行性,哪怕没学过网页设计的相关知识,本篇博客内容也是可以通过自己的努力操作出来了的(保姆级教学) 不过,还是当成图一乐来阅读吧,虽然它比直接点开浏览器 ...

  7. 写一个网页,支持10国语言便捷切换

    要创建一个支持10种语言便捷切换的网页,可以使用以下步骤: 为每种语言创建一个独立的HTML文件,文件名可以使用对应的语言代码表示(如"en.html"表示英文版). 在主页面上添 ...

  8. CSS写一个网页烟花特效并使用

    这是一个使用 CSS 实现网页烟花特效的例子: /* 给烟花容器设置样式 */ .fireworks {position: relative;height: 100vh;overflow: hidde ...

  9. 准备写一个Ibatisnet开发指南

    使用ibatisnet很久了,也积累了许多的零碎的资料,也有很多的朋友使用ibatisnet.感觉很有必要整理一下资料.我列了一下大纲: 前言.............. Ibatisnet介绍.. ...

最新文章

  1. word List 14
  2. 从attention到Transformer+CV中的self-attention
  3. 零日攻击的原理与防范方法
  4. 集成Tomcat环境到Eclipse中
  5. vscode使用Git Graph提交成功,但是仓库没有更新
  6. idea弹出Server‘s certificate is not trusted
  7. XCode下的iOS单元测试
  8. 实习踩坑之路:Git无法拉取最新分支代码?怎么解决?
  9. 国外大牛开发者创造出Siri第三方服务器
  10. ElementUI简单分页
  11. 2020年最值得收藏的60个AI开源工具
  12. 实验中常用光纤接头型号
  13. Access denied for user ‘bijian0530‘@‘localhost‘ (using password: YES)
  14. html5 embed居中,HTML5标签embed详解
  15. 台式电脑接路由器步骤_无线路由器连接台式电脑的方法
  16. 幼儿-知识与能力【1】
  17. iOS 自定义相机,拍照旋转
  18. python点图为什么显示不出来怎么办_Python底图不显示打印的点
  19. 用例测试(三)——边界值分析法
  20. 目标检测 AP计算 (回顾)

热门文章

  1. 海康IPCamera结合OpenCV图像处理的一般步骤
  2. 捕获海康威视IPCamera图像,转成OpenCV可以处理的图像(一)
  3. random.seed(seed)、np.random.seed(seed)、torch.manual_seed(seed)作用
  4. IT界须知的故事——仙童八叛徒
  5. asdasdasdaa
  6. Bonobo.Git.Server 401 Error
  7. 错误类型:reflection.ReflectionException: Could not set property ‘xxx‘ of ‘class ‘xxx‘ with value ‘xxx‘
  8. 中学计算机课注意事项,教育信息技术在初中物理课堂教学中的优点与注意事项...
  9. 浅谈PageRank算法
  10. 2007女足世界杯 巴西 vs 美国 之后