css3 点击爆炸下落
代码][JavaScript]代码
$(document).ready(function() {
// Generate the clips. In this case I'm using 5 (or 25 pieces)
(genClips = function() {
// For easy use
$t = $('.clipped-box');
// Like I said, we're using 5!
var amount = 5;
// Get the width of each clipped rectangle.
var width = $t.width() / amount;
var height = $t.height() / amount;
// The total is the square of the amount
var totalSquares = Math.pow(amount, 2);
// The HTML of the content
var html = $t.find('.content').html();
var y = 0;
for(var z = 0; z <= (amount*width); z = z+width) {
$('<div class="clipped" >'+html+'</div>').appendTo($t);
if(z === (amount*width)-width) {
y = y + height;
z = -width;
}
if(y === (amount*height)) {
z = 9999999;
}
}
})();
// A quick random function for selecting random numbers
function rand(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// A variable check for when the animation is mostly over
var first = false,
clicked = false;
// On click
$('.clipped-box div').on('click', function() {
if(clicked === false) {
clicked = true;
$('.clipped-box .content').css({'display' : 'none'});
// Apply to each clipped-box div.
$('.clipped-box div:not(.content)').each(function() {
// So the speed is a random speed between 90m/s and 120m/s. I know that seems like a lot
// But otherwise it seems too slow. That's due to how I handled the timeout.
var v = rand(120, 90),
angle = rand(80, 89), // The angle (the angle of projection) is a random number between 80 and 89 degrees.
theta = (angle * Math.PI) / 180, // Theta is the angle in radians
g = -9.8; // And gravity is -9.8. If you live on another planet feel free to change
// $(this) as self
var self = $(this);
// time is initially zero, also set some random variables. It's higher than the total time for the projectile motion
// because we want the squares to go off screen.
var t = 0,
z, r, nx, ny,
totalt = 15;
// The direction can either be left (1), right (-1) or center (0). This is the horizontal direction.
var negate = [1, -1, 0],
direction = negate[ Math.floor(Math.random() * negate.length) ];
// Some random numbers for altering the shapes position
var randDeg = rand(-5, 10),
randScale = rand(0.9, 1.1),
randDeg2 = rand(30, 5);
// Because box shadows are a bit laggy (by a bit I mean 'box shadows will not work on individual clipped divs at all')
// we're altering the background colour slightly manually, in order to give the divs differentiation when they are
// hovering around in the air.
var color = $(this).css('backgroundColor').split('rgb(')[1].split(')')[0].split(', '),
colorR = rand(-20, 20), // You might want to alter these manually if you change the color
colorGB = rand(-20, 20), // To get the right consistency.
newColor = 'rgb('+(parseFloat(color[0])+colorR)+', '+(parseFloat(color[1])+colorGB)+', '+(parseFloat(color[2])+colorGB)+')';
// And apply those
$(this).css({http://www.huiyi8.com/flashchajian/
'transform' : 'scale('+randScale+') skew('+randDeg+'deg) rotateZ('+randDeg2+'deg)',
'background' : newColorflash插件
});
// Set an interval
z = setInterval(function() {
// Horizontal speed is constant (no wind resistance on the internet)
var ux = ( Math.cos(theta) * v ) * direction;
// Vertical speed decreases as time increases before reaching 0 at its peak
var uy = ( Math.sin(theta) * v ) - ( (-g) * t);
// The horizontal position
nx = (ux * t);
// s = ut + 0.5at^2
ny = (uy * t) + (0.5 * (g) * Math.pow(t, 2));
// Apply the positions
$(self).css({'bottom' : (ny)+'px', 'left' : (nx)+'px'});
// Increase the time by 0.10
t = t + 0.10;
// If the time is greater than the total time clear the interval
if(t > totalt) {
clicked = false;
first = true;
$('.clipped-box').css({'top' : '-1000px', 'transition' : 'none'});
$(self).css({'left' : '0', 'bottom' : '0', 'opacity' : '1', 'transition' : 'none', 'transform' : 'none'});
// Finally clear the interval
clearInterval(z);
}
}, 10); // Run this interval every 10ms. Changing this will change the pace of the animation
});
}
});
r = setInterval(function() {
// This is a bit rough but it does the job
if(first === true) {
// I've just put this in so the deleted box will come down again after its been clicked.
// That way you can keep pressing delete.
$('.clipped-box').css({'top' : '0', 'transition' : ''});
$('.clipped-box div').css({'opacity' : '1', 'transition' : '', 'background-color' : ''});
$('.content').css({'display' : 'block'});
first = false;
}
}, 300);
});
css3 点击爆炸下落的更多相关文章
- HTML5+CSS3点击指定按钮显示某些内容效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 超厉害的CSS3图片破碎爆炸效果!
var fx = { buffer : function(obj, cur, target, fnDo, fnEnd, fs){ if(!fs)fs=6; var now={}; var x=0; ...
- 15款效果很酷的最新jQuery/CSS3特效
很久没来博客园发表文章了,今天就分享15款效果很酷的最新jQuery/CSS3特效,废话不说,一起来看看吧. 1.3D图片上下翻牌切换 一款基于jQuery+CSS3实现的3D图片上下翻牌切换效果,支 ...
- 手把手教你玩转CSS3 3D技术
手把手教你玩转 CSS3 3D 技术 要玩转css3的3d,就必须了解几个词汇,便是透视(perspective).旋转(rotate)和移动(translate).透视即是以现实的视角来看屏幕上 ...
- Solidworks如何生成爆炸图
1 自动爆炸 点击"爆炸视图"按钮,然后全部选中装配体(被选中的零件会变为蓝色,全部选中即全部变色)然后在组成偶尔的爆炸窗口中下拉,点击应用. 再点击完成 回到装配体面板, ...
- 10款让WEB前端开发人员更轻松的实用工具
这篇文章介绍10款让Web前端开发人员生活更轻松的实用工具.每个Web开发人员都有自己的工具箱,这样工作中碰到的每个问题都有一个好的解决方案供选择. 对于每一项工作,开发人员需要特定的辅助工具,所以如 ...
- 十款让 Web 前端开发人员更轻松的实用工具
这篇文章介绍十款让 Web 前端开发人员生活更轻松的实用工具.每个 Web 开发人员都有自己的工具箱,这样工作中碰到的每个问题都有一个好的解决方案供选择. 对于每一项工作,开发人员需要特定的辅助工具, ...
- JS实现别踩白块小游戏
最近有朋友找我用JS帮忙仿做一个别踩白块的小游戏程序,但他给的源代码较麻烦,而且没有注释,理解起来很无力,我就以自己的想法自己做了这个小游戏,主要是应用JS对DOM和数组的操作. 程序思路:如图:将游 ...
- 【转】十款让 Web 前端开发人员更轻松的实用工具
这篇文章介绍十款让 Web 前端开发人员生活更轻松的实用工具.每个 Web 开发人员都有自己的工具箱,这样工作中碰到的每个问题都有一个好的解决方案供选择. 对于每一项工作,开发人员需要特定的辅助工具, ...
随机推荐
- spring boot 使用拦截器 实现 用户登录拦截
登录拦截和和权限拦截实现类似 首先自定义一个[DefineAdapter]类,这个类我是用来放自定义的配置(比如 自定义请求参数,自定义拦截器等),集成WebMvcConfigurerAdapte ...
- Java内存模型FAQ(一) 什么是内存模型
原文:http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html 第一章 译者:方腾飞 在多核系统中,处理器一般有一层或者多层的缓存,这 ...
- mock测试类的时候,添加@InjectMocks
1.在单元测试某个类的时候,引入该类的时,添加注解@InjectMocks 2.该类的变量,需要添加注解:@Mock 3.类中需要第三方协作者时,通常会用到get和set方法注入.通过spring框架 ...
- __must_check必须处理函数返回值
include/linux/compiler-gcc4.h #define __must_check __attribute__((warn_unused_result)) _ ...
- strpos 判断字符串是否存在
strpos 中为什么要用逗号隔开的原因是因为 防止找出相匹配的中 , 如 查找1 而数组中 存在 12 那么这个结果也是可以找出来的 ,分别在1 前后加个, 就是为了区 ...
- Github上好的Android开源框架
1.volley 项目地址 https://github.com/smanikandan14/Volley-demo (1) JSON,图像等的异步下载: (2) 网络请求的排序(scheduli ...
- XmlDocument和XDocument转String
1:XDocument转String直接使用ToString();XNode里面重写了ToString()方法 2:XmlDocument转String需要写代码 using System; usin ...
- A norm is a function. 范数是函数。
[范数]范数是函数.A norm is a function.范数(norm),是具有“长度”概念的函数.在线性代数.泛函分析及相关的数学领域,是一个函数,其为向量空间内的所有向量赋予非零的正长度或大 ...
- mac 地址分配
https://regauth.standards.ieee.org/standards-ra-web/pub/view.html#registries 34:96:72:3c:5d:d6mac 地址 ...
- ShowModal 代码分析
下面为Delphi中,方法TCustomForm.ShowModal的代码,通过分析以下代码,可以了解ShowModal到底是怎么一回事! 1 2 3 4 5 6 7 8 9 10 11 12 13 ...