JQ烟花特效
JQ代码
1 /* 2 Template Name: 烟花特效 3 author: _犬's 4 url: http://mlldxe.cn/archives/541 5 */ 6 (function webpackUniversalModuleDefinition(root, factory) { 7 if (typeof exports === 'object' && typeof module === 'object') 8 module.exports = factory(); 9 else if (typeof define === 'function' && define.amd) 10 define([], factory); 11 else if (typeof exports === 'object') 12 exports["POWERMODE"] = factory(); 13 else 14 root["POWERMODE"] = factory() 15 } 16 )(this, function() { 17 return (function(modules) { 18 var installedModules = {}; 19 function __webpack_require__(moduleId) { 20 if (installedModules[moduleId]) 21 return installedModules[moduleId].exports; 22 var module = installedModules[moduleId] = { 23 exports: {}, 24 id: moduleId, 25 loaded: false 26 }; 27 modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 28 module.loaded = true; 29 return module.exports 30 } 31 __webpack_require__.m = modules; 32 __webpack_require__.c = installedModules; 33 __webpack_require__.p = ""; 34 return __webpack_require__(0) 35 } 36 )([function(module, exports, __webpack_require__) { 37 'use strict'; 38 var canvas = document.createElement('canvas'); 39 canvas.width = window.innerWidth; 40 canvas.height = window.innerHeight; 41 canvas.style.cssText = 'position:fixed;top:0;left:0;pointer-events:none;z-index:999999'; 42 window.addEventListener('resize', function() { 43 canvas.width = window.innerWidth; 44 canvas.height = window.innerHeight 45 }); 46 document.body.appendChild(canvas); 47 var context = canvas.getContext('2d'); 48 var particles = []; 49 var particlePointer = 0; 50 POWERMODE.shake = true; 51 function getRandom(min, max) { 52 return Math.random() * (max - min) + min 53 } 54 function getColor(el) { 55 if (POWERMODE.colorful) { 56 var u = getRandom(0, 360); 57 return 'hsla(' + getRandom(u - 10, u + 10) + ', 100%, ' + getRandom(50, 80) + '%, ' + 1 + ')' 58 } else { 59 return window.getComputedStyle(el).color 60 } 61 } 62 function getCaret() { 63 var el = document.activeElement; 64 var bcr; 65 if (el.tagName === 'TEXTAREA' || (el.tagName === 'INPUT' && el.getAttribute('type') === 'text')) { 66 var offset = __webpack_require__(1)(el, el.selectionStart); 67 bcr = el.getBoundingClientRect(); 68 return { 69 x: offset.left + bcr.left, 70 y: offset.top + bcr.top, 71 color: getColor(el) 72 } 73 } 74 var selection = window.getSelection(); 75 if (selection.rangeCount) { 76 var range = selection.getRangeAt(0); 77 var startNode = range.startContainer; 78 if (startNode.nodeType === document.TEXT_NODE) { 79 startNode = startNode.parentNode 80 } 81 bcr = range.getBoundingClientRect(); 82 return { 83 x: bcr.left, 84 y: bcr.top, 85 color: getColor(startNode) 86 } 87 } 88 return { 89 x: 0, 90 y: 0, 91 color: 'transparent' 92 } 93 } 94 function createParticle(x, y, color) { 95 return { 96 x: x, 97 y: y, 98 alpha: 1, 99 color: color, 100 velocity: { 101 x: -1 + Math.random() * 2, 102 y: -3.5 + Math.random() * 2 103 } 104 } 105 } 106 function POWERMODE() { 107 { 108 var caret = getCaret(); 109 var numParticles = 5 + Math.round(Math.random() * 10); 110 while (numParticles--) { 111 particles[particlePointer] = createParticle(caret.x, caret.y, caret.color); 112 particlePointer = (particlePointer + 1) % 500 113 } 114 } 115 { 116 if (POWERMODE.shake) { 117 var intensity = 1 + 2 * Math.random(); 118 var x = intensity * (Math.random() > 0.5 ? -1 : 1); 119 var y = intensity * (Math.random() > 0.5 ? -1 : 1); 120 document.body.style.marginLeft = x + 'px'; 121 document.body.style.marginTop = y + 'px'; 122 setTimeout(function() { 123 document.body.style.marginLeft = ''; 124 document.body.style.marginTop = '' 125 }, 75) 126 } 127 } 128 } 129 ;POWERMODE.colorful = false; 130 function loop() { 131 requestAnimationFrame(loop); 132 context.clearRect(0, 0, canvas.width, canvas.height); 133 for (var i = 0; i < particles.length; ++i) { 134 var particle = particles[i]; 135 if (particle.alpha <= 0.1) 136 continue; 137 particle.velocity.y += 0.075; 138 particle.x += particle.velocity.x; 139 particle.y += particle.velocity.y; 140 particle.alpha *= 0.96; 141 context.globalAlpha = particle.alpha; 142 context.fillStyle = particle.color; 143 context.fillRect(Math.round(particle.x - 1.5), Math.round(particle.y - 1.5), 3, 3) 144 } 145 } 146 requestAnimationFrame(loop); 147 module.exports = POWERMODE 148 } 149 , function(module, exports) { 150 (function() { 151 var properties = ['direction', 'boxSizing', 'width', 'height', 'overflowX', 'overflowY', 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', 'borderStyle', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'fontStyle', 'fontVariant', 'fontWeight', 'fontStretch', 'fontSize', 'fontSizeAdjust', 'lineHeight', 'fontFamily', 'textAlign', 'textTransform', 'textIndent', 'textDecoration', 'letterSpacing', 'wordSpacing', 'tabSize', 'MozTabSize']; 152 var isFirefox = window.mozInnerScreenX != null; 153 function getCaretCoordinates(element, position, options) { 154 var debug = options && options.debug || false; 155 if (debug) { 156 var el = document.querySelector('#input-textarea-caret-position-mirror-div'); 157 if (el) { 158 el.parentNode.removeChild(el) 159 } 160 } 161 var div = document.createElement('div'); 162 div.id = 'input-textarea-caret-position-mirror-div'; 163 document.body.appendChild(div); 164 var style = div.style; 165 var computed = window.getComputedStyle ? getComputedStyle(element) : element.currentStyle; 166 style.whiteSpace = 'pre-wrap'; 167 if (element.nodeName !== 'INPUT') 168 style.wordWrap = 'break-word'; 169 style.position = 'absolute'; 170 if (!debug) 171 style.visibility = 'hidden'; 172 properties.forEach(function(prop) { 173 style[prop] = computed[prop] 174 }); 175 if (isFirefox) { 176 if (element.scrollHeight > parseInt(computed.height)) 177 style.overflowY = 'scroll' 178 } else { 179 style.overflow = 'hidden' 180 } 181 div.textContent = element.value.substring(0, position); 182 if (element.nodeName === 'INPUT') 183 div.textContent = div.textContent.replace(/\s/g, "\u00a0"); 184 var span = document.createElement('span'); 185 span.textContent = element.value.substring(position) || '.'; 186 div.appendChild(span); 187 var coordinates = { 188 top: span.offsetTop + parseInt(computed['borderTopWidth']), 189 left: span.offsetLeft + parseInt(computed['borderLeftWidth']) 190 }; 191 if (debug) { 192 span.style.backgroundColor = '#aaa' 193 } else { 194 document.body.removeChild(div) 195 } 196 return coordinates 197 } 198 if (typeof module != "undefined" && typeof module.exports != "undefined") { 199 module.exports = getCaretCoordinates 200 } else { 201 window.getCaretCoordinates = getCaretCoordinates 202 } 203 }()) 204 } 205 ]) 206 });
调用
1 /* 鼠标特效 */ 2 var a_idx = 0; 3 jQuery(document).ready(function($) { 4 $("body").click(function(e) { 5 var a = new Array("富强", "民主","文明","和谐","自由","平等","公正","法治","爱国","敬业","诚信","友善"); 6 var $i = $("<span/>").text(a[a_idx]); 7 a_idx = (a_idx + 1) % a.length; 8 var x = e.pageX, 9 y = e.pageY; 10 $i.css({ 11 "z-index": 99999, 12 "top": y - 20, 13 "left": x, 14 "position": "absolute", 15 "font-weight": "bold", 16 "color": "#ff6651" 17 }); 18 $("body").append($i); 19 $i.animate({ 20 "top": y - 180, 21 "opacity": 0 22 }, 23 1500, 24 function() { 25 $i.remove(); 26 }); 27 }); 28 });
做你说过的 说你能做的;

浙公网安备 33010602011771号