1.evanyou效果-綵帶的實現,效果以下javascript
注:這個主要用的是Canvas畫布實現的,點擊背景繪製新的圖形,代碼以下: css
/*Html代碼:*/ <canvas id="evanyou" width="1920" height="934"></canvas> /*CSS代碼:*/ <style type="text/css"> #evanyou{ position:fixed; width:100%; height:100%; left:0; top:0; } </style> /*JS代碼:*/ // evanyou效果 var c = document.getElementById('evanyou'), x = c.getContext('2d'), pr = window.devicePixelRatio || 1, w = window.innerWidth, h = window.innerHeight, f = 90, q, m = Math, r = 0, u = m.PI * 2, v = m.cos, z = m.random; c.width = w * pr; c.height = h * pr; x.scale(pr, pr); x.globalAlpha = 0.6; function evanyou() { x.clearRect(0, 0, w, h) q = [{ x: 0, y: h * .7 + f }, { x: 0, y: h * .7 - f }] while (q[1].x < w + f) d(q[0], q[1]) } function d(i, j) { x.beginPath() x.moveTo(i.x, i.y) x.lineTo(j.x, j.y) var k = j.x + (z() * 2 - 0.25) * f, n = y(j.y) x.lineTo(k, n) x.closePath() r -= u / -50 x.fillStyle = '#' + (v(r) * 127 + 128 << 16 | v(r + u / 3) * 127 + 128 << 8 | v(r + u / 3 * 2) * 127 + 128).toString(16) x.fill() q[0] = q[1] q[1] = { x: k, y: n } } function y(p) { var t = p + (z() * 2 - 1.1) * f return (t > h || t < 0) ? y(p) : t } document.onclick = evanyou document.ontouchstart = evanyou evanyou();
2.返回頂部特效(滾動條上移或者點擊會自動隱藏和顯示),效果以下:html
使用到的圖片:java
代碼以下:http://files.cnblogs.com/files/shuai7boy/scroll.gifjquery
//Html代碼: body> <!--回到頂部--> <div id="back-to-top" class="red" data-scroll="body" style="top:-46px;color:red;">回到頂部 </div> <!--撐開網頁代碼--> <p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p> <p>hello</p><p>hello</p><p>hello</p> <p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p> <p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p> <p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p> <!--以上是撐開網頁代碼--> //CSS樣式 #back-to-top { position:fixed; right:50px; z-index:9; width:70px; height:900px; background:url('/Content/Images/scroll.png'); transition:0.5s; cursor:pointer; } //JS部分: <script src="~/Scripts/jquery-1.8.2.min.js"></script> <script type="text/javascript"> window.onload = function () { // 利用 data-scroll 屬性,滾動到任意 dom 元素 $.scrollto = function (scrolldom, scrolltime) { $(scrolldom).click(function () { var scrolltodom = $(this).attr("data-scroll"); $(this).addClass("active").siblings().removeClass("active"); $('html, body').animate({ scrollTop: $(scrolltodom).offset().top }, scrolltime); return false; }); }; //判斷位置控制 返回頂部的顯隱 if ($(window).width() > 800) {//若是窗體的寬度大於800 var backTo = $("#back-to-top");//獲取back-to-top對象 var backHeight = $(window).height() - 980 + 'px';//讓window高度減980 $(window).scroll(function () { if ($(window).scrollTop() > 700 && backTo.css('top') === '-900px') { backTo.css('top', backHeight); } else if ($(window).scrollTop() <= 700 && backTo.css('top') !== '-900px') { backTo.css('top', '-900px'); } }); } //啓用 $.scrollto("#back-to-top", 800); } </script>
3.左下角探頭效果web
PS:這個圖片在網頁的左下角,鼠標移動上去探頭效果,代碼以下canvas
//Html代碼 <div class="xm"> <img src="/Content/Images/xiaomai.png" /> </div> //CSS代碼 <style> .xm{ position:fixed; bottom:0; left:0; z-index:1; font-size:0; transition:all .3s ease-in-out; transform:translateY(3px); } .xm:hover{ -webkit-transform:translateY(0); -ms-transform:translateY(0); } .xm img{ width:50px; } </style>
4. 文字翻轉效果(點擊翻轉,一開始加載頁面也翻轉)ruby
代碼以下:app
//Html代碼 <header class="header-description"> <div id="site-header"> <h1> <a href="@Url.Action("JianJIe", "Home")" title="Anneke.cn">日月君地帶</a> </h1> <p class="typed"><a href="@Url.Action("JianJIe", "Home")" title="Anneke.cn">日月君地帶</a><span class="typed-cursor">|</span></p> </div> </header> //CSS代碼 <style type="text/css"> #site-header { font-size: 40px !important; font-weight: 700; z-index: 1; text-align: center; position: relative; top: 180px; font-family: kilsonburg,"Avenir Next",Helvetica,Arial,"Lantinghei SC","Microsoft YaHei",sans-serif; font-size: 34px; text-shadow: 0 1px 1px #47456d; margin-bottom: 130px; animation: show-site-title 1s ease-out; -o-animation: show-site-title 1s ease-out; -moz-animation: show-site-title 1s ease-out; -webkit-animation: show-site-title 1s ease-out; } #site-header h1 { display: none; } #site-header a { color: #fff; font-weight: 400; } body { background-color:#0094ff; } </style> //Script部分 $(document).ready(function ($) { $(".typed a").typed({ strings: ["這裏是地獄之門", "日月君地帶"], typeSpeed: 30, backSpeed: 30, backDelay: 700 }); }); //PS:須要引入兩個文件:一個是jquery-1.8.2.min.js文件,一個是 //typed.min.js文件(PS:自定義的,下面會貼出來)
typed.min.js代碼:dom
!function (t) { "use strict"; var s = function (s, e) { this.el = t(s), this.options = t.extend({}, t.fn.typed.defaults, e), this.isInput = this.el.is("input"), this.attr = this.options.attr, this.showCursor = this.isInput ? !1 : this.options.showCursor, this.elContent = this.attr ? this.el.attr(this.attr) : this.el.text(), this.contentType = this.options.contentType, this.typeSpeed = this.options.typeSpeed, this.startDelay = this.options.startDelay, this.backSpeed = this.options.backSpeed, this.backDelay = this.options.backDelay, this.stringsElement = this.options.stringsElement, this.strings = this.options.strings, this.strPos = 0, this.arrayPos = 0, this.stopNum = 0, this.loop = this.options.loop, this.loopCount = this.options.loopCount, this.curLoop = 0, this.stop = !1, this.cursorChar = this.options.cursorChar, this.shuffle = this.options.shuffle, this.sequence = [], this.build() }; s.prototype = { constructor: s, init: function () { var t = this; t.timeout = setTimeout(function () { for (var s = 0; s < t.strings.length; ++s) t.sequence[s] = s; t.shuffle && (t.sequence = t.shuffleArray(t.sequence)), t.typewrite(t.strings[t.sequence[t.arrayPos]], t.strPos) }, t.startDelay) }, build: function () { var s = this; if (this.showCursor === !0 && (this.cursor = t('<span class="typed-cursor">' + this.cursorChar + "</span>"), this.el.after(this.cursor)), this.stringsElement) { s.strings = [], this.stringsElement.hide(); var e = this.stringsElement.find("p"); t.each(e, function (e, i) { s.strings.push(t(i).html()) }) } this.init() }, typewrite: function (t, s) { if (this.stop !== !0) { var e = Math.round(70 * Math.random()) + this.typeSpeed, i = this; i.timeout = setTimeout(function () { var e = 0, r = t.substr(s); if ("^" === r.charAt(0)) { var o = 1; /^\^\d+/.test(r) && (r = /\d+/.exec(r)[0], o += r.length, e = parseInt(r)), t = t.substring(0, s) + t.substring(s + o) } if ("html" === i.contentType) { var n = t.substr(s).charAt(0); if ("<" === n || "&" === n) { var a = "", h = ""; for (h = "<" === n ? ">" : ";"; t.substr(s).charAt(0) !== h;) a += t.substr(s).charAt(0), s++; s++, a += h } } i.timeout = setTimeout(function () { if (s === t.length) { if (i.options.onStringTyped(i.arrayPos), i.arrayPos === i.strings.length - 1 && (i.options.callback(), i.curLoop++, i.loop === !1 || i.curLoop === i.loopCount)) return; i.timeout = setTimeout(function () { i.backspace(t, s) }, i.backDelay) } else { 0 === s && i.options.preStringTyped(i.arrayPos); var e = t.substr(0, s + 1); i.attr ? i.el.attr(i.attr, e) : i.isInput ? i.el.val(e) : "html" === i.contentType ? i.el.html(e) : i.el.text(e), s++, i.typewrite(t, s) } }, e) }, e) } }, backspace: function (t, s) { if (this.stop !== !0) { var e = Math.round(70 * Math.random()) + this.backSpeed, i = this; i.timeout = setTimeout(function () { if ("html" === i.contentType && ">" === t.substr(s).charAt(0)) { for (var e = ""; "<" !== t.substr(s).charAt(0) ;) e -= t.substr(s).charAt(0), s--; s--, e += "<" } var r = t.substr(0, s); i.attr ? i.el.attr(i.attr, r) : i.isInput ? i.el.val(r) : "html" === i.contentType ? i.el.html(r) : i.el.text(r), s > i.stopNum ? (s--, i.backspace(t, s)) : s <= i.stopNum && (i.arrayPos++, i.arrayPos === i.strings.length ? (i.arrayPos = 0, i.shuffle && (i.sequence = i.shuffleArray(i.sequence)), i.init()) : i.typewrite(i.strings[i.sequence[i.arrayPos]], s)) }, e) } }, shuffleArray: function (t) { var s, e, i = t.length; if (i) for (; --i;) e = Math.floor(Math.random() * (i + 1)), s = t[e], t[e] = t[i], t[i] = s; return t }, reset: function () { var t = this; clearInterval(t.timeout); var s = this.el.attr("id"); this.el.after('<span id="' + s + '"/>'), this.el.remove(), "undefined" != typeof this.cursor && this.cursor.remove(), t.options.resetCallback() } }, t.fn.typed = function (e) { return this.each(function () { var i = t(this), r = i.data("typed"), o = "object" == typeof e && e; r || i.data("typed", r = new s(this, o)), "string" == typeof e && r[e]() }) }, t.fn.typed.defaults = { strings: ["These are the default values...", "You know what you should do?", "Use your own!", "Have a great day!"], stringsElement: null, typeSpeed: 0, startDelay: 0, backSpeed: 0, shuffle: !1, backDelay: 500, loop: !1, loopCount: !1, showCursor: !0, cursorChar: "|", attr: null, contentType: "html", callback: function () { }, preStringTyped: function () { }, onStringTyped: function () { }, resetCallback: function () { } } }(window.jQuery);
5. 在離開網頁時,觸發事件(這裏以改變標題爲例)
注:這裏鼠標移開時,同時改變網頁title和icon圖標,代碼以下
//Head部分 <head> <meta name="viewport" content="width=device-width" /> <title>IT發燒友,一個真正的技術交流羣</title> <link rel="shortcut icon" href="/Content/Images/icon.png"> </head> //JS部分 <script src="~/Scripts/jquery-1.8.2.min.js"></script> <script> window.onload = function () { var OriginTitile = document.title; var titleTime; document.addEventListener('visibilitychange', function () { if (document.hidden) { $('[rel="shortcut icon"]').attr('href', "/Content/Images/fail.ico"); document.title = '(●—●)喔喲,崩潰啦!'; clearTimeout(titleTime); } else { $('[rel="shortcut icon"]').attr('href', "/Content/Images/icon.png"); document.title = '(/≧▽≦/)咦!又好了!' + OriginTitile; titleTime = setTimeout(function () { document.title = OriginTitile; }, 2000); } }); } </script>
6. 移入網頁時改變鼠標的樣式
PS:這個只要在樣式裏面設置便可,也就是移入時顯示一張圖片,代碼以下:
//css以下所示 <style> abbr, acronym, address, applet, article, aside, audio, b, big, blockquote, body, canvas, caption, center, cite, code, dd, del, details, dfn, dl, dt, em, embed, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, html, iframe, img, ins, kbd, label, legend, li, mark, menu, nav, object, ol, output, p, pre, q, ruby, s, samp, section, small, span, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, time, tr, tt, u, ul, var, video { margin: 0; padding: 0; cursor: url('/Content/Image/cursor.ico'),auto; } </style>
7. 文字向上滾動效果(PS:鼠標懸停中止滾動)
代碼以下:
//HTML代碼 <div align="center" id="demo"> <div id="demo1"> 我是滾動內容<br/> 你來抓我啊<br/> 嗖嗖嗖<br/> 2333333333333333333333333 </div> <div id="demo2"></div> </div> //CSS代碼: #demo{ overflow:hidden; height:200px; width:250px; border:1px solid #6699cc; font-size:14px; color:#336699; line-height:22px; text-align:left; padding:10px; } //JS代碼: var demo=document.getElementById("demo"); var demo1=document.getElementById("demo1"); var demo2=document.getElementById("demo2"); var speed=30;//滾動速度值,值越大速度越慢 var nnn=200/demo1.offsetHeight; for(i=0;i<nnn;i++){demo1.innerHTML+="<br />"+ demo1.innerHTML} demo2.innerHTML = demo1.innerHTML //克隆demo2爲demo1 function Marquee(){ if(demo2.offsetTop-demo.scrollTop<=0) //當滾動至demo1與demo2交界時 demo.scrollTop-=demo1.offsetHeight //demo跳到最頂端 else{ demo.scrollTop++ //若是是橫向的 將 全部的 height top 改爲 width left } } var MyMar = setInterval(Marquee,speed); //設置定時器 demo.onmouseover = function(){clearInterval(MyMar)} //鼠標通過時清除定時器達到滾動中止的目的 demo.onmouseout = function(){MyMar = setInterval(Marquee,speed)} //鼠標移開時重設定時器
8.鼠標移入效果
PS:鼠標移入,使區域旋轉變色
//Style樣式 <link href="~/Content/amazeui.min.css" rel="stylesheet" /> <style type="text/css"> #XuanZhuan li{ width:200px; height:50px; background-color:pink; margin-left:15px; position:relative; float:left; list-style:none; margin-top:15px; } div{ width:470px; } #XuanZhuan li:hover{ cursor:pointer; } </style> //Html標籤 <div> <ul id="XuanZhuan"> <li> 11111111111111111 </li> <li> 222222222222222 </li> <li> 333333333333333 </li> <li> 4444444444444444 </li> </ul> </div> //Script <script src="~/Scripts/jquery-1.8.2.min.js"></script> <script type="text/javascript"> //在友情連接頁面,鼠標放在li上,li旋轉效果 $(function () { $("#XuanZhuan li").hover(function () { $(this).css("background-color", "yellow"); $(this).attr("class", "am-animation-spin"); }, function () { $(this).css("background-color", "pink"); $(this).attr("class", ""); }); }) </script>
引入amazeui.min.css樣式以下:
連接:http://pan.baidu.com/s/1qY1YinU 密碼:tjox
9.旋轉星空,點擊放煙花效果
實現代碼:
//Html代碼 <div> <canvas id="canvas"></canvas> <canvas id="snow"></canvas> <div class="am-g" style="position: fixed; bottom: 0px;"> <div class="am-u-sm-12"> <div style="z-index: 9999" id="player" class="aplayer"> </div> </div> </div> </div> //CSS代碼 canvas { position: fixed; width: 100%; height: 100%; z-index: -1; } //引入JS <script src="~/Content/assets/js/jquery.min.js"></script> <script src="~/Scripts/Blog/universe.js"></script><!--旋轉背景--> <script src="~/Scripts/Blog/Fireworks.js"></script><!--點擊放煙花-->
universe.js
var canvas = document.getElementById('canvas'), ctx = canvas.getContext('2d'), w = canvas.width = window.innerWidth, h = canvas.height = window.innerHeight, hue = 217, stars = [], count = 0, maxStars = 1300;//星星數量 var canvas2 = document.createElement('canvas'), ctx2 = canvas2.getContext('2d'); canvas2.width = 100; canvas2.height = 100; var half = canvas2.width / 2, gradient2 = ctx2.createRadialGradient(half, half, 0, half, half, half); gradient2.addColorStop(0.025, '#CCC'); gradient2.addColorStop(0.1, 'hsl(' + hue + ', 61%, 33%)'); gradient2.addColorStop(0.25, 'hsl(' + hue + ', 64%, 6%)'); gradient2.addColorStop(1, 'transparent'); ctx2.fillStyle = gradient2; ctx2.beginPath(); ctx2.arc(half, half, half, 0, Math.PI * 2); ctx2.fill(); // End cache function random(min, max) { if (arguments.length < 2) { max = min; min = 0; } if (min > max) { var hold = max; max = min; min = hold; } return Math.floor(Math.random() * (max - min + 1)) + min; } function maxOrbit(x, y) { var max = Math.max(x, y), diameter = Math.round(Math.sqrt(max * max + max * max)); return diameter / 2; //星星移動範圍,值越大範圍越小, } var Star = function () { this.orbitRadius = random(maxOrbit(w, h)); this.radius = random(60, this.orbitRadius) / 8; //星星大小 this.orbitX = w / 2; this.orbitY = h / 2; this.timePassed = random(0, maxStars); this.speed = random(this.orbitRadius) / 50000; //星星移動速度 this.alpha = random(2, 10) / 10; count++; stars[count] = this; } Star.prototype.draw = function () { var x = Math.sin(this.timePassed) * this.orbitRadius + this.orbitX, y = Math.cos(this.timePassed) * this.orbitRadius + this.orbitY, twinkle = random(10); if (twinkle === 1 && this.alpha > 0) { this.alpha -= 0.05; } else if (twinkle === 2 && this.alpha < 1) { this.alpha += 0.05; } ctx.globalAlpha = this.alpha; ctx.drawImage(canvas2, x - this.radius / 2, y - this.radius / 2, this.radius, this.radius); this.timePassed += this.speed; } for (var i = 0; i < maxStars; i++) { new Star(); } function animation() { ctx.globalCompositeOperation = 'source-over'; ctx.globalAlpha = 0.5; //尾巴 ctx.fillStyle = 'hsla(' + hue + ', 64%, 6%, 2)'; ctx.fillRect(0, 0, w, h) ctx.globalCompositeOperation = 'lighter'; for (var i = 1, l = stars.length; i < l; i++) { stars[i].draw(); canvas2.style.cssText = "display:none"; }; window.requestAnimationFrame(animation); } animation();
Fireworks.js
$(function () { var Fireworks = function () { var self = this; var rand = function (rMi, rMa) { return ~~((Math.random() * (rMa - rMi + 1)) + rMi); } var hitTest = function (x1, y1, w1, h1, x2, y2, w2, h2) { return !(x1 + w1 < x2 || x2 + w2 < x1 || y1 + h1 < y2 || y2 + h2 < y1); }; window.requestAnimFrame = function () { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (a) { window.setTimeout(a, 1E3 / 60) } }(); self.init = function () { self.canvas = document.createElement('canvas'); self.canvas.width = self.cw = $(window).innerWidth(); self.canvas.height = self.ch = $(window).innerHeight(); self.particles = []; self.partCount = 150; self.fireworks = []; self.mx = self.cw / 2; self.my = self.ch / 2; self.currentHue = 30; self.partSpeed = 5; self.partSpeedVariance = 10; self.partWind = 50; self.partFriction = 5; self.partGravity = 1; self.hueMin = 0; self.hueMax = 360; self.fworkSpeed = 4; self.fworkAccel = 10; self.hueVariance = 30; self.flickerDensity = 25; self.showShockwave = true; self.showTarget = false; self.clearAlpha = 25; $(document.body).append(self.canvas); self.ctx = self.canvas.getContext('2d'); self.ctx.lineCap = 'round'; self.ctx.lineJoin = 'round'; self.lineWidth = 1; self.bindEvents(); self.canvasLoop(); self.canvas.onselectstart = function () { return false; }; }; self.createParticles = function (x, y, hue) { var countdown = self.partCount; while (countdown--) { var newParticle = { x: x, y: y, coordLast: [ { x: x, y: y }, { x: x, y: y }, { x: x, y: y } ], angle: rand(0, 360), speed: rand(((self.partSpeed - self.partSpeedVariance) <= 0) ? 1 : self.partSpeed - self.partSpeedVariance, (self.partSpeed + self.partSpeedVariance)), friction: 1 - self.partFriction / 100, gravity: self.partGravity / 2, hue: rand(hue - self.hueVariance, hue + self.hueVariance), brightness: rand(50, 80), alpha: rand(40, 100) / 100, decay: rand(10, 50) / 1000, wind: (rand(0, self.partWind) - (self.partWind / 2)) / 25, lineWidth: self.lineWidth }; self.particles.push(newParticle); } }; self.updateParticles = function () { var i = self.particles.length; while (i--) { var p = self.particles[i]; var radians = p.angle * Math.PI / 180; var vx = Math.cos(radians) * p.speed; var vy = Math.sin(radians) * p.speed; p.speed *= p.friction; p.coordLast[2].x = p.coordLast[1].x; p.coordLast[2].y = p.coordLast[1].y; p.coordLast[1].x = p.coordLast[0].x; p.coordLast[1].y = p.coordLast[0].y; p.coordLast[0].x = p.x; p.coordLast[0].y = p.y; p.x += vx; p.y += vy; p.y += p.gravity; p.angle += p.wind; p.alpha -= p.decay; if (!hitTest(0, 0, self.cw, self.ch, p.x - p.radius, p.y - p.radius, p.radius * 2, p.radius * 2) || p.alpha < .05) { self.particles.splice(i, 1); } }; }; self.drawParticles = function () { var i = self.particles.length; while (i--) { var p = self.particles[i]; var coordRand = (rand(1, 3) - 1); self.ctx.beginPath(); self.ctx.moveTo(Math.round(p.coordLast[coordRand].x), Math.round(p.coordLast[coordRand].y)); self.ctx.lineTo(Math.round(p.x), Math.round(p.y)); self.ctx.closePath(); self.ctx.strokeStyle = 'hsla(' + p.hue + ', 100%, ' + p.brightness + '%, ' + p.alpha + ')'; self.ctx.stroke(); if (self.flickerDensity > 0) { var inverseDensity = 50 - self.flickerDensity; if (rand(0, inverseDensity) === inverseDensity) { self.ctx.beginPath(); self.ctx.arc(Math.round(p.x), Math.round(p.y), rand(p.lineWidth, p.lineWidth + 3) / 2, 0, Math.PI * 2, false) self.ctx.closePath(); var randAlpha = rand(50, 100) / 100; self.ctx.fillStyle = 'hsla(' + p.hue + ', 100%, ' + p.brightness + '%, ' + randAlpha + ')'; self.ctx.fill(); } } }; }; self.createFireworks = function (startX, startY, targetX, targetY) { var newFirework = { x: startX, y: startY, startX: startX, startY: startY, hitX: false, hitY: false, coordLast: [ { x: startX, y: startY }, { x: startX, y: startY }, { x: startX, y: startY } ], targetX: targetX, targetY: targetY, speed: self.fworkSpeed, angle: Math.atan2(targetY - startY, targetX - startX), shockwaveAngle: Math.atan2(targetY - startY, targetX - startX) + (90 * (Math.PI / 180)), acceleration: self.fworkAccel / 100, hue: self.currentHue, brightness: rand(50, 80), alpha: rand(50, 100) / 100, lineWidth: self.lineWidth }; self.fireworks.push(newFirework); }; self.updateFireworks = function () { var i = self.fireworks.length; while (i--) { var f = self.fireworks[i]; self.ctx.lineWidth = f.lineWidth; vx = Math.cos(f.angle) * f.speed, vy = Math.sin(f.angle) * f.speed; f.speed *= 1 + f.acceleration; f.coordLast[2].x = f.coordLast[1].x; f.coordLast[2].y = f.coordLast[1].y; f.coordLast[1].x = f.coordLast[0].x; f.coordLast[1].y = f.coordLast[0].y; f.coordLast[0].x = f.x; f.coordLast[0].y = f.y; if (f.startX >= f.targetX) { if (f.x + vx <= f.targetX) { f.x = f.targetX; f.hitX = true; } else { f.x += vx; } } else { if (f.x + vx >= f.targetX) { f.x = f.targetX; f.hitX = true; } else { f.x += vx; } } if (f.startY >= f.targetY) { if (f.y + vy <= f.targetY) { f.y = f.targetY; f.hitY = true; } else { f.y += vy; } } else { if (f.y + vy >= f.targetY) { f.y = f.targetY; f.hitY = true; } else { f.y += vy; } } if (f.hitX && f.hitY) { self.createParticles(f.targetX, f.targetY, f.hue); self.fireworks.splice(i, 1); } }; }; self.drawFireworks = function () { var i = self.fireworks.length; self.ctx.globalCompositeOperation = 'lighter'; while (i--) { var f = self.fireworks[i]; self.ctx.lineWidth = f.lineWidth; var coordRand = (rand(1, 3) - 1); self.ctx.beginPath(); self.ctx.moveTo(Math.round(f.coordLast[coordRand].x), Math.round(f.coordLast[coordRand].y)); self.ctx.lineTo(Math.round(f.x), Math.round(f.y)); self.ctx.closePath(); self.ctx.strokeStyle = 'hsla(' + f.hue + ', 100%, ' + f.brightness + '%, ' + f.alpha + ')'; self.ctx.stroke(); if (self.showTarget) { self.ctx.save(); self.ctx.beginPath(); self.ctx.arc(Math.round(f.targetX), Math.round(f.targetY), rand(1, 8), 0, Math.PI * 2, false) self.ctx.closePath(); self.ctx.lineWidth = 1; self.ctx.stroke(); self.ctx.restore(); } if (self.showShockwave) { self.ctx.save(); self.ctx.translate(Math.round(f.x), Math.round(f.y)); self.ctx.rotate(f.shockwaveAngle); self.ctx.beginPath(); self.ctx.arc(0, 0, 1 * (f.speed / 5), 0, Math.PI, true); self.ctx.strokeStyle = 'hsla(' + f.hue + ', 100%, ' + f.brightness + '%, ' + rand(25, 60) / 100 + ')'; self.ctx.lineWidth = f.lineWidth; self.ctx.stroke(); self.ctx.restore(); } }; }; self.bindEvents = function () { $(window).on('resize', function () { clearTimeout(self.timeout); self.timeout = setTimeout(function () { self.canvas.width = self.cw = $(window).innerWidth(); self.canvas.height = self.ch = $(window).innerHeight(); self.ctx.lineCap = 'round'; self.ctx.lineJoin = 'round'; }, 100); }); $(self.canvas).on('mousedown', function (e) { self.mx = e.pageX - self.canvas.offsetLeft; self.my = e.pageY - self.canvas.offsetTop; self.currentHue = rand(self.hueMin, self.hueMax); self.createFireworks(self.cw / 2, self.ch, self.mx, self.my); $(self.canvas).on('mousemove.fireworks', function (e) { self.mx = e.pageX - self.canvas.offsetLeft; self.my = e.pageY - self.canvas.offsetTop; self.currentHue = rand(self.hueMin, self.hueMax); self.createFireworks(self.cw / 2, self.ch, self.mx, self.my); }); }); $(self.canvas).on('mouseup', function (e) { $(self.canvas).off('mousemove.fireworks'); }); } self.clear = function () { self.particles = []; self.fireworks = []; self.ctx.clearRect(0, 0, self.cw, self.ch); }; self.canvasLoop = function () { requestAnimFrame(self.canvasLoop, self.canvas); self.ctx.globalCompositeOperation = 'destination-out'; self.ctx.fillStyle = 'rgba(0,0,0,' + self.clearAlpha / 100 + ')'; self.ctx.fillRect(0, 0, self.cw, self.ch); self.updateFireworks(); self.updateParticles(); self.drawFireworks(); self.drawParticles(); }; self.init(); } var fworks = new Fireworks(); });
10.音樂播放組件-APlayer
PS:此插件由迅雷提供,實現以下:
//Html代碼 <div id="player1" class="aplayer"> <pre class="aplayer-lrc-content"> [ti:斷橋殘雪] [ar:Vae] [al:斷橋殘雪(EP)] [00:01.90]Vae - 斷橋殘雪 [00:05.16]詞、曲 編曲:許嵩(Vae) [00:08.16] [00:24.99]尋不到花的折翼枯葉蝶 [00:30.09]永遠也看不見凋謝 [00:36.90]江南夜色下的小橋屋檐 [00:42.04]讀不懂塞北的荒野 [00:48.94]梅開時節因寂寞而纏綿 [00:54.07]春歸後又很快湮滅 [01:01.21]獨留我賞煙花飛滿天 [01:06.03]搖曳後就隨風飄遠 [01:13.11]斷橋是否下過雪 [01:15.83]我望着湖面 [01:18.77]水中寒月如雪 [01:21.78]指尖輕點融解 [01:24.81]斷橋是否下過雪 [01:27.69]又想起你的臉 [01:30.66]如果無緣再見 [01:33.75]白堤柳簾垂淚好幾遍 [02:03.83]尋不到花的折翼枯葉蝶 [02:09.12]永遠也看不見凋謝 [02:15.84]江南夜色下的小橋屋檐 [02:21.17]讀不懂塞北的荒野 [02:28.01]梅開時節因寂寞而纏綿 [02:33.09]春歸後又很快湮滅 [02:39.79]獨留我賞煙花飛滿天 [02:45.19]搖曳後就隨風飄遠 [02:52.06]斷橋是否下過雪 [02:54.83]我望着湖面 [02:57.80]水中寒月如雪 [03:00.82]指尖輕點融解 [03:03.85]斷橋是否下過雪 [03:06.83]又想起你的臉 [03:09.90]如果無緣再見 [03:12.74]白堤柳簾垂淚好幾遍 <!-- ... --> </pre> </div> //JS部分 <script type="text/javascript"> //初始化APlayer音樂播放器插件。 var ap = new APlayer({ element: document.getElementById('player1'), narrow: false, autoplay: false, //是否自動播放 showlrc: true, //是否顯示歌詞 theme: '#66B7FF', //主題顏色 music: { title: '斷橋殘雪', author: '許嵩大人', url: '/Content/Music/許嵩 - 斷橋殘雪.mp3', pic: '/Content/Music/dqcx.jpg', } }); ap.init(); </script> //引入JS部分 <script src="~/Scripts/jquery-1.8.2.min.js"></script> <link href="//cdn.bootcss.com/aplayer/1.4.8/APlayer.min.css" rel="stylesheet"> <script src="//cdn.bootcss.com/aplayer/1.4.8/APlayer.min.js"></script>
11.點擊彈出指定的內容
PS:點擊彈出顯示內容,過一會自動消失,說白了也就是一個彈出內容插件,比alert好看些,代碼以下
//Html代碼 <input type="button" value="顯示獲取到的內容" id="btn1"/> //JS代碼 <script src="~/Scripts/jquery-1.8.2.min.js"></script> <script src="~/Scripts/layer/layer.js"></script> <script type="text/javascript"> $(function () { $("#btn1").click(function () { layer.msg("我是彈出的內容"); }); }) </script>
layer.js引入連接:http://pan.baidu.com/s/1geTeA8F 密碼:uabe
利用上面的插件還能夠實現confirm選擇效果
實現代碼:
layer.confirm('肯定要刪除?', { icon: 3, title: '提示' }, function () { alert("固然肯定了~"); });
PS:上面的彈框點擊後必須添加 layer.closeAll("dialog");纔會關閉
12.每天飛鳥
上面這是個網頁小遊戲,在網頁中引入簡單的圖片JS便可開始啦~
實現以下:
連接:http://pan.baidu.com/s/1o7V85oI 密碼:qvu3