Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body{overflow: hidden} canvas { background: linear-gradient( hsl(200, 50%, 80%) 0%, hsl(200, 30%, 95%) 75%) ; display: block; } div { height: 100%; left: 0; position: fixed; top: 0; width: 100%; }
JavaScript
(function() { var Building, Skyline, dt, sketch, skylines; sketch = Sketch.create(); sketch.mouse.x = sketch.width / 10; sketch.mouse.y = sketch.height; skylines = []; dt = 1; // BUILDINGS Building = function(config) { return this.reset(config); }; Building.prototype.reset = function(config) { this.layer = config.layer; this.x = config.x; this.y = config.y; this.width = config.width; this.height = config.height; this.color = config.color; this.slantedTop = floor(random(0, 10)) === 0; this.slantedTopHeight = this.width / random(2, 4); this.slantedTopDirection = round(random(0, 1)) === 0; this.spireTop = floor(random(0, 15)) === 0; this.spireTopWidth = random(this.width * .01, this.width * .07); this.spireTopHeight = random(10, 20); this.antennaTop = !this.spireTop && floor(random(0, 10)) === 0; this.antennaTopWidth = this.layer / 2; return this.antennaTopHeight = random(5, 20); }; Building.prototype.render = function() { sketch.fillStyle = sketch.strokeStyle = this.color; sketch.lineWidth = 2; sketch.beginPath(); sketch.rect(this.x, this.y, this.width, this.height); sketch.fill(); sketch.stroke(); if (this.slantedTop) { sketch.beginPath(); sketch.moveTo(this.x, this.y); sketch.lineTo(this.x + this.width, this.y); if (this.slantedTopDirection) { sketch.lineTo(this.x + this.width, this.y - this.slantedTopHeight); } else { sketch.lineTo(this.x, this.y - this.slantedTopHeight); } sketch.closePath(); sketch.fill(); sketch.stroke(); } if (this.spireTop) { sketch.beginPath(); sketch.moveTo(this.x + (this.width / 2), this.y - this.spireTopHeight); sketch.lineTo(this.x + (this.width / 2) + this.spireTopWidth, this.y); sketch.lineTo(this.x + (this.width / 2) - this.spireTopWidth, this.y); sketch.closePath(); sketch.fill(); sketch.stroke(); } if (this.antennaTop) { sketch.beginPath(); sketch.moveTo(this.x + (this.width / 2), this.y - this.antennaTopHeight); sketch.lineTo(this.x + (this.width / 2), this.y); sketch.lineWidth = this.antennaTopWidth; return sketch.stroke(); } }; // SKYLINES Skyline = function(config) { this.x = 0; this.buildings = []; this.layer = config.layer; this.width = { min: config.width.min, max: config.width.max }; this.height = { min: config.height.min, max: config.height.max }; this.speed = config.speed; this.color = config.color; this.populate(); return this; }; Skyline.prototype.populate = function() { var newHeight, newWidth, results, totalWidth; totalWidth = 0; results = []; while (totalWidth <= sketch.width + (this.width.max * 2)) { newWidth = round(random(this.width.min, this.width.max)); newHeight = round(random(this.height.min, this.height.max)); this.buildings.push(new Building({ layer: this.layer, x: this.buildings.length === 0 ? 0 : this.buildings[this.buildings.length - 1].x + this.buildings[this.buildings.length - 1].width, y: sketch.height - newHeight, width: newWidth, height: newHeight, color: this.color })); results.push(totalWidth += newWidth); } return results; }; Skyline.prototype.update = function() { var firstBuilding, lastBuilding, newHeight, newWidth; this.x -= (sketch.mouse.x * this.speed) * dt; firstBuilding = this.buildings[0]; if (firstBuilding.width + firstBuilding.x + this.x < 0) { newWidth = round(random(this.width.min, this.width.max)); newHeight = round(random(this.height.min, this.height.max)); lastBuilding = this.buildings[this.buildings.length - 1]; firstBuilding.reset({ layer: this.layer, x: lastBuilding.x + lastBuilding.width, y: sketch.height - newHeight, width: newWidth, height: newHeight, color: this.color }); return this.buildings.push(this.buildings.shift()); } }; Skyline.prototype.render = function() { var i; i = this.buildings.length; sketch.save(); sketch.translate(this.x, (sketch.height - sketch.mouse.y) / 20 * this.layer); while (i--) { this.buildings[i].render(i); } return sketch.restore(); }; // SETUP sketch.setup = function() { var i, results; i = 5; results = []; while (i--) { results.push(skylines.push(new Skyline({ layer: i + 1, width: { min: (i + 1) * 30, max: (i + 1) * 40 }, height: { min: 150 - (i * 35), max: 300 - (i * 35) }, speed: (i + 1) * .003, color: 'hsl( 200, ' + (((i + 1) * 1) + 10) + '%, ' + (75 - (i * 13)) + '% )' }))); } return results; }; // CLEAR sketch.clear = function() { return sketch.clearRect(0, 0, sketch.width, sketch.height); }; // UPDATE sketch.update = function() { var i, results; dt = sketch.dt < .1 ? .1 : sketch.dt / 16; dt = dt > 5 ? 5 : dt; i = skylines.length; results = []; while (i--) { results.push(skylines[i].update(i)); } return results; }; // DRAW sketch.draw = function() { var i, results; i = skylines.length; results = []; while (i--) { results.push(skylines[i].render(i)); } return results; }; // Mousemove Fix $(window).on('mousemove', function(e) { sketch.mouse.x = e.pageX; return sketch.mouse.y = e.pageY; }); }).call(this);
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>画布视差天际线-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号