跟隨鼠標(biāo)的動(dòng)態(tài)光環(huán),當(dāng)鼠標(biāo)停止后逐漸圍繞鼠標(biāo)形成一個(gè)大的“星星”,許多跟隨鼠標(biāo)移動(dòng)的小星星組成一定的圖案,十分漂亮,主要是運(yùn)用JS技術(shù)實(shí)現(xiàn)的鼠標(biāo)特效,DIV+CSS布局,符合WEB標(biāo)準(zhǔn)。
演示:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>跟隨鼠標(biāo)移動(dòng)的流星</title><meta http-equiv="content-type" content="text/html;charset=gb2312"><style type="text/css">html{overflow:hidden;}body{position:absolute;height:100%;width:100%;margin:0;padding:0;}#screen{background:#000;position:absolute;width:100%;height:100%;}#screen span{background:#fff;font-size:0;overflow:hidden;width:2px;height:2px;}</style><script type="text/javascript">var Follow = function () {var $ = function (i) {return document.getElementById(i)},addEvent = function (o, e, f) {o.addEventListener ? o.addEventListener(e, f, false) : o.attachEvent('on'+e, function(){f.call(o)})},OBJ = [], sp, rs, N = 0, m;var init = function (id, config) {this.config = config || {};this.obj = $(id);sp = this.config.speed || 4;rs = this.config.animR || 1;m = {x: $(id).offsetWidth * .5, y: $(id).offsetHeight * .5};this.setXY();this.start();}init.prototype = {setXY : function () {var _this = this;addEvent(this.obj, 'mousemove', function (e) {e = e || window.event;m.x = e.clientX;m.y = e.clientY;})},start : function () {var k = 180 / Math.PI, OO, o, _this = this, fn = this.config.fn;OBJ[N++] = OO = new CObj(null, 0, 0);for(var i=0;i<360;i+=20){var O = OO;for(var j=10; j<35; j+=1){var x = fn(i, j).x,y = fn(i, j).y;OBJ[N++] = o = new CObj(O , x, y);O = o;}}setInterval(function() {for (var i = 0; i < N; i++) OBJ[i].run();}, 16);}}var CObj = function (p, cx, cy) {var obj = document.createElement("span");this.css = obj.style;this.css.position = "absolute";this.css.left = "-1000px";this.css.zIndex = 1000 - N;document.getElementById("screen").appendChild(obj);this.ddx = 0;this.ddy = 0;this.PX = 0;this.PY = 0;this.x = 0;this.y = 0;this.x0 = 0;this.y0 = 0;this.cx = cx;this.cy = cy;this.parent = p;}CObj.prototype.run = function () {if (!this.parent) {this.x0 = m.x;this.y0 = m.y;} else {this.x0 = this.parent.x;this.y0 = this.parent.y;}this.x = this.PX += (this.ddx += ((this.x0 - this.PX - this.ddx) + this.cx) / rs) / sp;this.y = this.PY += (this.ddy += ((this.y0 - this.PY - this.ddy) + this.cy) / rs) / sp;this.css.left = Math.round(this.x) + 'px';this.css.top = Math.round(this.y) + 'px';}return init;}();</script></head><body><div id="screen"></div><script type="text/javascript">new Follow('screen', {speed: 4,animR : 2,fn : function (i, j) {return {x : j/4*Math.cos(i),y : j/4*Math.sin(i)}}})</script></body></html><div style="text-align:center;margin:30px 0 0 0;"><hr style="color:#999;height:1px;">如不能顯示效果,請(qǐng)按Ctrl+F5刷新本頁,更多網(wǎng)頁代碼:<a href='http://www.jyygyx.com/' target='_blank'>http://www.jyygyx.com/</a></div>提示:可修改后代碼再運(yùn)行!
上一篇 堅(jiān)持≠勝利 只有熟悉的專業(yè)建站方能成功
下一篇 JS 判斷 iframe 是否加載完成的代碼
程序員人生,我編程,我富裕,記住wfuyu網(wǎng),php教程,php學(xué)習(xí),php手冊(cè),CMS模版制作
聲明:本站大部分內(nèi)容是作者原創(chuàng),少部分收集于互聯(lián)網(wǎng)供大家一起學(xué)習(xí),原版權(quán)很多不明,如有侵權(quán)請(qǐng)聯(lián)系本站,謝謝!
粵ICP備14040726號(hào)-1?? 2015-2020 程序員人生 版權(quán)所有