欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jQuery实现炫丽的3d旋转星空效果

程序员文章站 2023-12-26 13:48:45
本文实例讲述了jquery实现炫丽的3d旋转星空效果。分享给大家供大家参考,具体如下: 该特效也是在jquery插件库中找到的,感觉效果不错,说不定以后项目中要有绚丽的星...

本文实例讲述了jquery实现炫丽的3d旋转星空效果。分享给大家供大家参考,具体如下:

该特效也是在jquery插件库中找到的,感觉效果不错,说不定以后项目中要有绚丽的星空背景,拿来即用,收藏了下。

下载解压后的目录结构

jQuery实现炫丽的3d旋转星空效果

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.com/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 top 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;
   top: 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/stopexecutionontimeout.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.shouldstopexecution(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>

运行的效果如下:

jQuery实现炫丽的3d旋转星空效果

其中stopexecutionontimeout.js如下:

复制代码 代码如下:
"use strict";"object"!=typeof window.cp&&(window.cp={}),window.cp.pentimer={programnolongerbeingmonitored:!1,timeoffirstcalltoshouldstoploop: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},shouldstoploop:function(o){if(this.programkilledsostopmonitoring)return!0;if(this.programnolongerbeingmonitored)return!1;if(this._loopexits[o])return!1;var t=this._gettime();if(0===this.timeoffirstcalltoshouldstoploop)return this.timeoffirstcalltoshouldstoploop=t,!1;var i=t-this.timeoffirstcalltoshouldstoploop;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.programkilledsostopmonitoring=!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._throwanerrortostoppen()}catch(t){this._throwanerrortostoppen()}},_shouldpostmessage:function(){return document.location.href.match(/boomerang/)},_throwanerrortostoppen:function(){throw"we found an infinite loop in your pen. we've stopped 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.shouldstopexecution=function(o){return window.cp.pentimer.shouldstoploop(o)},window.cp.exitedloop=function(o){window.cp.pentimer.exitedloop(o)};

效果还是挺不错的,你可以改变背景颜色等等定制。

更多关于jquery相关内容感兴趣的读者可查看本站专题:《jquery切换特效与技巧总结》、《jquery扩展技巧总结》、《jquery常用插件及用法总结》、《jquery常见经典特效汇总》、《jquery动画与特效用法总结》及《jquery选择器用法总结

希望本文所述对大家jquery程序设计有所帮助。

上一篇:

下一篇: