jquery投色子动画
可以点击这里体验效果:http://keleyi.com/keleyi/phtml/jqtexiao/26.htm
效果图:

代码如下:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>jQuery掷色子并显示随机结果-可乐义</title>
<style type="text/css">
#main_keleyi_com{width:800px;margin: 0px auto;}
.demo{width:760px; height:120px; margin:0px auto;}
.wrap{width:90px; height:90px; margin:20px auto 30px auto; position:relative}
.dice{width:90px; height:90px; background:url(http://keleyi.com/image/a/hwwnhj7b.png) no-repeat; cursor:pointer;}
.dice_1{background-position:-5px -4px}
.dice_2{background-position:-5px -107px}
.dice_3{background-position:-5px -212px}
.dice_4{background-position:-5px -317px}
.dice_5{background-position:-5px -427px}
.dice_6{background-position:-5px -535px}
.dice_t{background-position:-5px -651px}
.dice_s{background-position:-5px -763px}
.dice_e{background-position:-5px -876px}
p#result{text-align:center; font-size:16px}
p#result span{font-weight:bold; color:#f30; margin:6px}
#dice_mask{width:90px; height:90px; background:#fff; opacity:0; position:absolute; top:0; left:0; z-index:999}
</style>
<script type="text/javascript" src="http://keleyi.com/keleyi/pmedia/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(function () {
var dice = $("#dice");
dice.click(function () {
$(".wrap").append("<div id='dice_mask'></div>"); //加遮罩
dice.attr("class", "dice"); //清除上次动画后的点数
dice.css('cursor', 'default');
var num = Math.floor(Math.random() * 6 + 1); //产生随机数1-6
dice.animate({ left: '+2px' }, 100, function () {
dice.addClass("dice_t");
}).delay(200).animate({ top: '-2px' }, 100, function () {
dice.removeClass("dice_t").addClass("dice_s");
}).delay(200).animate({ opacity: 'show' }, 600, function () {
dice.removeClass("dice_s").addClass("dice_e");
}).delay(100).animate({ left: '-2px', top: '2px' }, 100, function () {
dice.removeClass("dice_e").addClass("dice_" + num);
$("#result").html("您掷得点数是<span>" + num + "</span>");
dice.css('cursor', 'pointer');
$("#dice_mask").remove(); //移除遮罩
});
});
});
</script>
</head>
<body>
<div id="main_keleyi_com">
<h2 class="top_title">jQuery掷色子并显示随机结果</h2>
请点击色子: <div class="demo">
<div class="wrap">
<div id="dice" class="dice dice_1"></div>
</div>
<p id="result">请直接点击上面的色子!</p>
</div>
<a href="http://keleyi.com/a/bjad/vxywlkah.htm" target="_blank">原文</a>
</div>
</body>
</html>
例子中,动画效果是使用jquery的animate函数实现的,请参考:http://keleyi.com/a/bjac/5b62295315de9ace.htm
而用到的Math.floor是取整数,详情请参考:http://keleyi.com/a/bjad/s0ix7ao1.htm
还用到append方法,append() 方法在被选元素的结尾(仍然在内部)插入指定内容,详情请参考http://keleyi.com/a/bjac/0vpch15n.htm
而removeClass方法和addClass方法请参考:http://keleyi.com/a/bjac/e9e40a974de5a902.htm
Web前端资源汇总:http://www.cnblogs.com/jihua/p/webfront.html
jquery投色子动画的更多相关文章
- 投色子--html demo
这是之前客户想要看的一个效果,不知道放在博客里面有没有关系,当做备份吧. <!DOCTYPE HTML> <html> <head> <meta charse ...
- jquery的animate({})动画整理
在网页制作的过程中少不了用到各种动画,形式多种多样,flash,css,js,canvas,等等都能实现,对于其优劣和效果只能说各有千秋. 什么是动画效果,其实网页中的渐变效果就是一种很基础的动画,动 ...
- 适应手机端的jQuery图片滑块动画DEMO演示
在线预览 下载地址 实例代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt ...
- jQuery学习笔记(四)jQuery中的动画
目录 show()方法和hide()方法 fideIn()方法和fadeOut()方法 slideUp方法和slideDown()方法 自定义动画方法animate toogle(),slideTog ...
- 8款超绚丽的jQuery焦点图动画
随着前端技术和浏览器技术的不断发展,人们开始对网页视觉效果的要求越来越高.我们经常会在页面中看到很多炫酷的图片焦点图播放控件,有些甚至是大屏的焦点图占用大片的页面空间,从而吸引用户的眼球.本文要分享的 ...
- 第五章 jQuery中的动画
通过jQuery中的动画方法,能轻松地为网页添加精彩的视觉效果,给用户一种全新体验. 1.show()方法和hide()方法 该方法的功能与css()方法设置display属性效果相同. 给show( ...
- JQuery中的动画
一.show()方法和hide()方法 这两种方法是jQuery动画的最基本方法.当为元素调用show方法时相当于将该元素的display样式改为block或者inline,同理,如果当元素调用hid ...
- 八款强大的jQuery图片滑块动画插件
jQuery是一款相当轻巧的JavaScript框架,目前几乎每一个WEB项目都在使用jQuery,因为jQuery插件实在太丰富,尤其是 一些图片滑块插件和jQuery焦点图插件,更是多如牛毛,很多 ...
- jQuery中animate动画第二次点击事件没反应
jQuery中animate动画第二次点击事件没反应 用animate做点击翻页动画时发现第二次点击事件动画没反应,而第一次点击有动画效果,代码如下: 复制代码 代码如下: $(".page ...
随机推荐
- Android笔记——关于Cursor类的介绍
使用过 SQLite数据库的童鞋对 Cursor 应该不陌生,加深自己和大家对Android 中使用 Cursor 的理解. 关于 Cursor 在你理解和使用 Android Cursor 的时候你 ...
- Kafka随笔一
一.KafKa所涉及到的名词概念: 1. Topic:用于划分Message的逻辑概念,一个Topic可以分布在多个Broker上. 2. Partition:是Kafka中横向扩展和一切 ...
- Building OpenCascade on Windows with Visual Studio
Building OpenCascade on Windows with Visual Studio eryar@163.com 摘要Abstract:详细说明OpenCascade的编译配置过程,希 ...
- Gridview里添加合计行
ShowFooter="true" ; ; ; protected void gvIncomeYG_RowDataBound(object sender, GridViewRowE ...
- Panorama和Pivot的区别
Panorama 1.提供了更丰富的用户体验(建议最多4个Items项) 2.Item可以设置屏幕方向为水平,支持多于一个屏幕的显示 3.可以使用任意大小的背景图片,Panorama会自动地缩放为屏幕 ...
- IOS学习之初识KVC
什么是kvc? kvc (key-value coding )键值编码,是ios 提供的一种通过key间接的来访问对象属性的一直方式. 哪些类支持kvc操作? kvc的操作方法由NSKeyValueC ...
- IDDD 实现领域驱动设计-由贫血导致的失忆症
啰嗦几句 年前的时候,在和 netfocus 兄,以及对 DDD 感兴趣园友的探讨过程中,我发现自己有很多不足的地方,对 DDD 的了解也只是皮毛而已,代码写的少,DDD 的基本概念也不是很清楚,空有 ...
- spring源码分析之定时任务概述
Spring框架提供了TaskExcutor的异步执行和TashScheduler的任务定时执行接口,同样spring也提供了线程池或者CommonJ的代理. TaskExecutor的类型 Simp ...
- cordova plugin add出现CERT_UNTRUSTED错误解决方法
介绍 目前使用ionic+cordova完成hybmid app开发,在安装geolocation插件时爆出来一个莫名的错误: Fetching from npm failed: CERT_UNTRU ...
- Apple的LZF算法解析
有关LZF算法的相关解析文档比较少,但是Apple对LZF的开源,可以让我们对该算法进行一个简单的解析.LZFSE 基于 Lempel-Ziv ,并使用了有限状态熵编码.LZF采用类似lz77和lzs ...