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 开发人员都有自己的工具箱,这样工作中碰到的每个问题都有一个好的解决方案供选择. 对于每一项工作,开发人员需要特定的辅助工具, ...
随机推荐
- 常见Linux/Unix开发辅助命令什锦
很多零碎命令集锦: 1. 怎样通过命令下载ftp文件 read -s -p "Your passwd: " Passwd; wget --user=YourUserName --p ...
- 好员工去哪儿了:高端IT白领荒胜过春节保姆荒
来自:http://tech.163.com/14/0312/07/9N4BLV8S000915BD.html 于是,你看到的就是这样一幕悖论:一群手握大把工作机会的雇主,在面对一群眼巴巴等待工作机会 ...
- nl 命令
nl命令在linux系统中用来计算文件中行号.nl 可以将输出的文件内容自动的加上行号!其默认的结果与 cat -n 有点不太一样, nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐 0 等 ...
- 【数据挖掘】聚类之k-means(转载)
[数据挖掘]聚类之k-means 1.算法简述 分类是指分类器(classifier)根据已标注类别的训练集,通过训练可以对未知类别的样本进行分类.分类被称为监督学习(supervised learn ...
- LNMP环境搭建之php安装,wordpress博客搭建
LNMP环境搭建之php安装,wordpress博客搭建 一.介绍: 1.什么是CGI CGI全称是"通用网关接口"(Common Gateway Interface),HTTP服 ...
- ubuntu 16.04安装visual studio code 提示libnss3版本低:NSS >= 3.26 is required
Linux Ubuntu 1604安装VS CODE之后,执行./code报错误: [3781:0914/160851.489979:FATAL:nss_util.cc(632)] NSS_Versi ...
- Java研发工程师面试题
基础题 一.String,StringBuffer, StringBuilder 的区别是什么?String为什么是不可变的?1. String是字符串常量,StringBuffer和StringBu ...
- python入门课程 第一章 课程介绍
1-1 Python入门课程介绍特点: 优雅.明确.简单适合领域: web网站和各种网络服务 系统工具和脚本 作为"胶水"语言把其他语言开发的模块包装起来方 ...
- python tensorflow 学习
Tensorflow系列——Saver的用法:http://blog.csdn.net/u011500062/article/details/51728830 Tensorflow学习系列(二): t ...
- lua(简单的传参)
#include <iostream> #include <string.h> extern "C" { /*头文件lua.h定义了Lua提供的基础函数,包 ...