• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >jquery > jquery制作 随机弹跳的小球特效

jquery制作 随机弹跳的小球特效

作者: 字体:[增加 减小] 来源:互联网 时间:2017-08-16

通过本文主要向大家介绍了jquery,随机,弹跳,小球等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

以下是源码:

 <!doctype html>
 <html>
 <head>
 <title>HTML5 随机弹跳的小球</title>
 <style>
 body{
 font-family: 微软雅黑;   
 }
 body,h1{
 margin:0;
 }
 canvas{
 display:block;margin-left: auto;margin-right: auto;
 border:1px solid #DDD;   
 background: -webkit-linear-gradient(top, #222,#111);
 }   
 </style>
 </head>
 <body>
 <h1>HTML5特效 随机弹跳的小球</h1>
 <div>请使用支持HTML5的浏览器开打本页。 <button id="stop-keleyi-com">暂停</button>
 <button id="run-keleyi-com">继续</button>
 <button id="addBall-keleyi-com">增加小球</button> <button onclick="javascript:window.location.reload();">刷新</button>
 <br />每次刷新页面的小球大小,颜色,运动路线,都是新的,可以点击上面各个按钮看看效果。
 </div>
 <canvas id="canvas-keleyi-com" >
 </canvas>
 <script type="text/javascript" src="http://keleyi.com/keleyi/pmedia/jquery/jquery-1.11.0.min.js"></script>
 <script type="text/javascript">
 var nimo = {
 aniamted: null,
 content: null,
 data: {
 radiusRange: [5, 20],
 speedRange: [-5, 5],
 scrollHeight: null,
 scrollWdith: null
 },
 balls: [],
 ele: {
 canvas: null
 },
 fn: {
 creatRandom: function (startInt, endInt) {//生产随机数
 var iResult;
 iResult = startInt + (Math.floor(Math.random() * (endInt - startInt + 1)));
 return iResult
 },
 init: function () {
 nimo.data.scrollWdith = document.body.scrollWidth;
 nimo.data.scrollHeight = document.body.scrollHeight;
 nimo.ele.canvas = document.getElementById('canvas-ke'+'leyi-com');
 nimo.content = nimo.ele.canvas.getContext('2d');
 nimo.ele.canvas.width = nimo.data.scrollWdith - 50;
 nimo.ele.canvas.height = nimo.data.scrollHeight - 100;
 },
 addBall: function () {
 var aRandomColor = [];
 aRandomColor.push(nimo.fn.creatRandom(0, 255));
 aRandomColor.push(nimo.fn.creatRandom(0, 255));
 aRandomColor.push(nimo.fn.creatRandom(0, 255));
 var iRandomRadius = nimo.fn.creatRandom(nimo.data.radiusRange[0], nimo.data.radiusRange[1]);
 var oTempBall = {
 coordsX: nimo.fn.creatRandom(iRandomRadius, nimo.ele.canvas.width - iRandomRadius),
 coordsY: nimo.fn.creatRandom(iRandomRadius, nimo.ele.canvas.height - iRandomRadius),
 radius: iRandomRadius,
 bgColor: 'rgba(' + aRandomColor[0] + ',' + aRandomColor[1] + ',' + aRandomColor[2] + ',0.5)'
 };
 oTempBall.speedX = nimo.fn.creatRandom(nimo.data.speedRange[0], nimo.data.speedRange[1]);
 if (oTempBall.speedX === 0) {
 oTempBall.speedX = 1
 }
 if (oTempBall.speedY === 0) {
 oTempBall.speedY = 1
 }
 oTempBall.speedY = nimo.fn.creatRandom(nimo.data.speedRange[0], nimo.data.speedRange[1]);
 nimo.balls.push(oTempBall)
 },
 drawBall: function (bStatic) {
 var i, iSize;
 nimo.content.clearRect(0, 0, nimo.ele.canvas.width, nimo.ele.canvas.height)
 for (var i = 0, iSize = nimo.balls.length; i < iSize; i++) {
 var oTarger = nimo.balls[i];
 nimo.content.beginPath();
 nimo.content.arc(oTarger.coordsX, oTarger.coordsY, oTarger.radius, 0, 10);
 nimo.content.fillStyle = oTarger.bgColor;
 nimo.content.fill();
 if (!bStatic) {
 if (oTarger.coordsX + oTarger.radius >= nimo.ele.canvas.width) {
 oTarger.speedX = -(Math.abs(oTarger.speedX))
 }
 if (oTarger.coordsX - oTarger.radius <= 0) {
 oTarger.speedX = Math.abs(oTarger.speedX)
 }
 if (oTarger.coordsY - oTarger.radius <= 0) {
 oTarger.speedY = Math.abs(oTarger.speedY)
 }
 if (oTarger.coordsY + oTarger.radius >= nimo.ele.canvas.height) {
 oTarger.speedY = -(Math.abs(oTarger.speedY))
 }
 oTarger.coordsX = oTarger.coordsX + oTarger.speedX;
 oTarger.coordsY = oTarger.coordsY + oTarger.speedY;
 }
 }
 },
 run: function () {
 nimo.fn.drawBall();
 nimo.aniamted = setTimeout(function () {
 nimo.fn.drawBall();
 nimo.aniamted = setTimeout(arguments.callee, 10)
 }, 10)
 },
 stop: function () {
 clearTimeout(nimo.aniamted)
 }
 }
 }
 window.onload = function () {
 nimo.fn.init();
 var i;
 for (var i = 0; i < 10; i++) {
 nimo.fn.addBall();
 }
 nimo.fn.run();
 document.getElementById('stop-kel'+'eyi-com').onclick = function () {
 nimo.fn.stop()
 }
 document.getElementById('run-keley'+'i-com').onclick = function () {
 nimo.fn.stop()
 nimo.fn.run()
 }
 document.getElementById('addBall-k'+'eleyi-com').onclick = function () {
 var i;
 for (var i = 0; i < 10; i++) {
 nimo.fn.addBall();
 }
 nimo.fn.drawBall(true);
 }
 }
 </script>
 </body>
 </html>

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 基于jQuery对象和DOM对象和字符串之间的转化实例
  • jquery+css实现简单的图片轮播效果
  • 使用jQuery实现鼠标点击左右按钮滑动切换
  • jQuery实现上传图片前预览效果功能
  • jQuery初级教程之网站品牌列表效果
  • 基于jquery实现多选下拉列表
  • jQuery接受后台传递的List的实例详解
  • 详解jquery选择器的原理
  • jQuery上传插件webupload使用方法
  • 关于jquery form表单序列化的注意事项详解

相关文章

  • 2017-08-16jquery img src 获取实现代码
  • 2017-08-16jQuery Validate表单验证深入学习
  • 2017-08-16jQuery实现的产品自动360度旋转展示特效源码分享
  • 2017-08-16jquery代码实现简单的随机图片瀑布流效果
  • 2017-08-16Jquery Easyui搜索框组件SearchBox使用详解(19)
  • 2017-08-16解决jquery的datepicker的本地化以及Today问题
  • 2017-08-16jQuery中Ajax的get、post等方法详解
  • 2017-08-16分享几个超级震憾的图片特效
  • 2017-08-16jQuery中closest()函数用法实例
  • 2017-08-16jquery实现图片灯箱明暗的遮罩效果

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • JQuery插入DOM节点的方法
    • 了解jQuery技巧来提高你的代码(个人觉得那个jquery的手册很不错)
    • CSS3,HTML5和jQuery搜索框集锦
    • jQuery封装的获取Url中的Get参数示例
    • JQuery.Ajax之错误调试帮助信息介绍
    • jQuery.form.js的使用详解
    • jQuery中remove()方法用法实例
    • Jquery全屏相册插件zoomvisualizer具有调节放大与缩小功能
    • html、css和jquery相结合实现简单的进度条效果实例代码
    • jQuery 版本的文本输入框检查器Input Check

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有