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不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
2026赚钱平台入口大全
2026赚钱平台入口大全

2026年最新赚钱平台入口汇总,涵盖任务众包、内容创作、电商运营、技能变现等多类正规渠道,助你轻松开启副业增收之路。阅读专题下面的文章了解更多详细内容。

33

2026.01.31

高干文在线阅读网站大全
高干文在线阅读网站大全

汇集热门1v1高干文免费阅读资源,涵盖都市言情、京味大院、军旅高干等经典题材,情节紧凑、人物鲜明。阅读专题下面的文章了解更多详细内容。

32

2026.01.31

无需付费的漫画app大全
无需付费的漫画app大全

想找真正免费又无套路的漫画App?本合集精选多款永久免费、资源丰富、无广告干扰的优质漫画应用,涵盖国漫、日漫、韩漫及经典老番,满足各类阅读需求。阅读专题下面的文章了解更多详细内容。

36

2026.01.31

漫画免费在线观看地址大全
漫画免费在线观看地址大全

想找免费又资源丰富的漫画网站?本合集精选2025-2026年热门平台,涵盖国漫、日漫、韩漫等多类型作品,支持高清流畅阅读与离线缓存。阅读专题下面的文章了解更多详细内容。

7

2026.01.31

漫画防走失登陆入口大全
漫画防走失登陆入口大全

2026最新漫画防走失登录入口合集,汇总多个稳定可用网址,助你畅享高清无广告漫画阅读体验。阅读专题下面的文章了解更多详细内容。

11

2026.01.31

php多线程怎么实现
php多线程怎么实现

PHP本身不支持原生多线程,但可通过扩展如pthreads、Swoole或结合多进程、协程等方式实现并发处理。阅读专题下面的文章了解更多详细内容。

1

2026.01.31

php如何运行环境
php如何运行环境

本合集详细介绍PHP运行环境的搭建与配置方法,涵盖Windows、Linux及Mac系统下的安装步骤、常见问题及解决方案。阅读专题下面的文章了解更多详细内容。

0

2026.01.31

php环境变量如何设置
php环境变量如何设置

本合集详细讲解PHP环境变量的设置方法,涵盖Windows、Linux及常见服务器环境配置技巧,助你快速掌握环境变量的正确配置。阅读专题下面的文章了解更多详细内容。

0

2026.01.31

php图片如何上传
php图片如何上传

本合集涵盖PHP图片上传的核心方法、安全处理及常见问题解决方案,适合初学者与进阶开发者。阅读专题下面的文章了解更多详细内容。

2

2026.01.31

热门下载

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

精品课程

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

共18课时 | 5万人学习

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

共102课时 | 6.8万人学习

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

共132课时 | 10万人学习

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

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