0

0

分享一个css3 点击爆炸下落的特效代码

零下一度

零下一度

发布时间:2017-04-26 17:39:14

|

3424人浏览过

|

来源于php中文网

原创

一个代码简洁,效果明显的jquery+css3特效 点击div块状,会自动破碎并散落到网页底部 

[图片] 

分享一个css3 点击爆炸下落的特效代码

[代码]

$(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) { 
		
			$('

'+html+'

').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 p').on('click', function() { if(clicked === false) { clicked = true; $('.clipped-box .content').css({'display' : 'none'}); // Apply to each clipped-box p. $('.clipped-box p: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 inpidual clipped ps at all') // we're altering the background colour slightly manually, in order to give the ps 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({ 'transform' : 'scale('+randScale+') skew('+randDeg+'deg) rotateZ('+randDeg2+'deg)', 'background' : newColor }); // 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 p').css({'opacity' : '1', 'transition' : '', 'background-color' : ''}); $('.content').css({'display' : 'block'}); first = false; } }, 300); });

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
C++ 设计模式与软件架构
C++ 设计模式与软件架构

本专题深入讲解 C++ 中的常见设计模式与架构优化,包括单例模式、工厂模式、观察者模式、策略模式、命令模式等,结合实际案例展示如何在 C++ 项目中应用这些模式提升代码可维护性与扩展性。通过案例分析,帮助开发者掌握 如何运用设计模式构建高质量的软件架构,提升系统的灵活性与可扩展性。

14

2026.01.30

c++ 字符串格式化
c++ 字符串格式化

本专题整合了c++字符串格式化用法、输出技巧、实践等等内容,阅读专题下面的文章了解更多详细内容。

9

2026.01.30

java 字符串格式化
java 字符串格式化

本专题整合了java如何进行字符串格式化相关教程、使用解析、方法详解等等内容。阅读专题下面的文章了解更多详细教程。

12

2026.01.30

python 字符串格式化
python 字符串格式化

本专题整合了python字符串格式化教程、实践、方法、进阶等等相关内容,阅读专题下面的文章了解更多详细操作。

4

2026.01.30

java入门学习合集
java入门学习合集

本专题整合了java入门学习指南、初学者项目实战、入门到精通等等内容,阅读专题下面的文章了解更多详细学习方法。

20

2026.01.29

java配置环境变量教程合集
java配置环境变量教程合集

本专题整合了java配置环境变量设置、步骤、安装jdk、避免冲突等等相关内容,阅读专题下面的文章了解更多详细操作。

18

2026.01.29

java成品学习网站推荐大全
java成品学习网站推荐大全

本专题整合了java成品网站、在线成品网站源码、源码入口等等相关内容,阅读专题下面的文章了解更多详细推荐内容。

19

2026.01.29

Java字符串处理使用教程合集
Java字符串处理使用教程合集

本专题整合了Java字符串截取、处理、使用、实战等等教程内容,阅读专题下面的文章了解详细操作教程。

3

2026.01.29

Java空对象相关教程合集
Java空对象相关教程合集

本专题整合了Java空对象相关教程,阅读专题下面的文章了解更多详细内容。

6

2026.01.29

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
CSS3 教程
CSS3 教程

共18课时 | 5万人学习

HTML5/CSS3/JavaScript/ES6入门课程
HTML5/CSS3/JavaScript/ES6入门课程

共102课时 | 6.8万人学习

HTML+CSS基础与实战
HTML+CSS基础与实战

共132课时 | 9.9万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号