jQuery实现炫丽的3d旋转星空效果
网络编程 2021-07-04 16:45www.168986.cn编程入门
这篇文章主要介绍了jQuery实现炫丽的3d旋转星空效果,涉及jQuery数值运算与页面元素属性动态变换相关操作技巧,需要的朋友可以参考下
本文实例讲述了jQuery实现炫丽的3d旋转星空效果。分享给大家供大家参考,具体如下
该特效也是在Jquery插件库中找到的,感觉效果不错,说不定以后项目中要有绚丽的星空背景,拿来即用,收藏了下。
下载解压后的目录结构
index.html页面代码
<!doctype html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>jQuery和CSS3超绚丽的3D星空动画特效</title> <script src="http://libs.baidu./jquery/2.0.0/jquery.min.js"></script> <style class="cp-pen-styles">body { background: radial-gradient(200% 100% at bottom center, #0070aa, #0b2570, #000035, #000); background: radial-gradient(220% 105% at center, #000 10%, #000035 40%, #0b2570 65%, #0070aa); background-attachment: fixed; overflow: hidden; } @keyframes rotate { 0% { transform: perspective(400px) rotateZ(20deg) rotateX(-40deg) rotateY(0); } 100% { transform: perspective(400px) rotateZ(20deg) rotateX(-40deg) rotateY(-360deg); } } .stars { transform: perspective(500px); transform-style: preserve-3d; position: absolute; bottom: 0; perspective-origin: 50% 100%; left: 50%; animation: rotate 90s infinite linear; } .star { width: 2px; height: 2px; background: #F7F7B6; position: absolute; : 0; left: 0; transform-origin: 0 0 -300px; transform: translate3d(0, 0, -300px); backface-visibility: hidden; } </style> </head> <body> <div class="stars"> </div> <script src='js/sExecutionOnTimeout.js'></script> <script> $(document).ready(function () { var stars = 800; var $stars = $('.stars'); var r = 800; for (var i = 0; i < stars; i++) { if (window.CP.shouldSExecution(1)) { break; } var $star = $('<div/>').addClass('star'); $stars.append($star); } window.CP.exitedLoop(1); $('.star').each(function () { var cur = $(this); var s = 0.2 + Math.random() 1; var curR = r + Math.random() 300; cur.css({ transformOrigin: '0 0 ' + curR + 'px', transform: ' translate3d(0,0,-' + curR + 'px) rotateY(' + Math.random() 360 + 'deg) rotateX(' + Math.random() -50 + 'deg) scale(' + s + ',' + s + ')' }); }); }); </script> </body> </html>
运行的效果如下
其中sExecutionOnTimeout.js如下
代码如下:
"use strict";"object"!=typeof window.CP&&(window.CP={}),window.CP.PenTimer={programNoLongerBeingMonitored:!1,timeOfFirstCallToShouldSLoop:0,_loopExits:{},_loopTimers:{},START_MONITORING_AFTER:2e3,STOP_ALL_MONITORING_TIMEOUT:5e3,MAX_TIME_IN_LOOP_WO_EXIT:2200,exitedLoop:function(o){this._loopExits[o]=!0},shouldSLoop:function(o){if(this.programKilledSoSMonitoring)return!0;if(this.programNoLongerBeingMonitored)return!1;if(this._loopExits[o])return!1;var t=this._getTime();if(0===this.timeOfFirstCallToShouldSLoop)return this.timeOfFirstCallToShouldSLoop=t,!1;var i=t-this.timeOfFirstCallToShouldSLoop;if(i<this.START_MONITORING_AFTER)return!1;if(i>this.STOP_ALL_MONITORING_TIMEOUT)return this.programNoLongerBeingMonitored=!0,!1;try{this._checkOnInfiniteLoop(o,t)}catch(n){return this._sendErrorMessageToEditor(),this.programKilledSoSMonitoring=!0,!0}return!1},_sendErrorMessageToEditor:function(){try{if(this._shouldPostMessage()){var o={action:"infinite-loop",line:this._findAroundLineNumber()};parent.postMessage(JSON.stringify(o),"")}else this._throwAnErrorToSPen()}catch(t){this._throwAnErrorToSPen()}},_shouldPostMessage:function(){return document.location.href.match(/boomerang/)},_throwAnErrorToSPen:function(){throw"We found an infinite loop in your Pen. We've sped the Pen from running. Please correct it or contact support@codepen.io."},_findAroundLineNumber:function(){var o=new Error,t=0;if(o.stack){var i=o.stack.match(/boomerang\S+:(\d+):\d+/);i&&(t=i[1])}return t},_checkOnInfiniteLoop:function(o,t){if(!this._loopTimers[o])return this._loopTimers[o]=t,!1;var i=t-this._loopTimers[o];if(i>this.MAX_TIME_IN_LOOP_WO_EXIT)throw"Infinite Loop found on loop: "+o},_getTime:function(){return+new Date}},window.CP.shouldSExecution=function(o){return window.CP.PenTimer.shouldSLoop(o)},window.CP.exitedLoop=function(o){window.CP.PenTimer.exitedLoop(o)};
效果还是挺不错的,你可以改变背景颜色等等定制。
更多关于jQuery相关内容感兴趣的读者可查看本站专题《》、《》、《》、《》、《》及《》
希望本文所述对大家jQuery程序设计有所帮助。
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指