seajs官方小实例
一.目录结构
二.代码
hello.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Hello Sea.js</title> <link rel="stylesheet" href="style.css"> </head> <body> <div id="container"> <img src="https://i.alipayobjects.com/e/201211/1cqKb32QfE.png" width="44" height="44" alt="H"> <img src="https://i.alipayobjects.com/e/201211/1cqKb2rJHI.png" width="44" height="44" alt="e"> <img src="https://i.alipayobjects.com/e/201211/1cqKeZrUpg.png" width="44" height="44" alt="l"> <img src="https://i.alipayobjects.com/e/201211/1cqM4u3Ejk.png" width="44" height="44" alt="l"> <img src="https://i.alipayobjects.com/e/201211/1cqKoKV2Sa.png" width="44" height="44" alt="o"> <img src="https://i.alipayobjects.com/e/201211/1cqKb4JU4K.png" width="44" height="44" alt=","> <img src="https://i.alipayobjects.com/e/201211/1cqKojFDLY.png" width="44" height="44" alt="S"> <img src="https://i.alipayobjects.com/e/201211/1cqKb2sBO8.png" width="44" height="44" alt="e"> <img src="https://i.alipayobjects.com/e/201211/1cqKb2LmXk.png" width="44" height="44" alt="a"> <img src="https://i.alipayobjects.com/e/201211/1cqKb1jcWC.png" width="44" height="44" alt="J"> <img src="https://i.alipayobjects.com/e/201211/1cqKojb72y.png" width="44" height="44" alt="S"> </div> <script src="sea-modules/sea.js"></script> <script> // Set configuration seajs.config({ base: "./sea-modules/", alias: { "jquery": "jquery/jquery/1.10.1/jquery.js" } }); seajs.use("./main"); </script> </body> </html>
main.js
define(function(require) { var Spinning = require('./spinning'); var s = new Spinning('#container'); s.render(); });
spinning.js
define(function(require, exports, module) { var $ = require('jquery'); function Spinning(container) { this.container = $(container); this.icons = this.container.children(); this.spinnings = []; } module.exports = Spinning; Spinning.prototype.render = function() { this._init(); this.container.css('background', 'none'); this.icons.show(); this._spin(); } Spinning.prototype._init = function() { var spinnings = this.spinnings; $(this.icons).each(function(n) { var startDeg = random(360); var node = $(this); var timer; node.css({ top: random(40), left: n * 50 + random(10), zIndex: 1000 }).hover( function() { node.fadeTo(250, 1) .css('zIndex', 1001) .css('transform', 'rotate(0deg)'); }, function() { node.fadeTo(250, .6).css('zIndex', 1000); timer && clearTimeout(timer); timer = setTimeout(spin, Math.ceil(random(10000))); } ); function spin() { node.css('transform', 'rotate(' + startDeg + 'deg)'); } spinnings[n] = spin; }) return this; } Spinning.prototype._spin = function() { $(this.spinnings).each(function(i, fn) { setTimeout(fn, Math.ceil(random(3000))); }); return this; } function random(x) { return Math.random() * x }; });
三.运行结果
seajs官网:http://seajs.org/docs/
相关推荐
binglingnew 2020-02-09
人生百态 2020-02-02
binglingnew 2012-10-03
yo跟着新宇走 2020-01-03
binglingnew 2019-12-03
Gary的影响力 2014-01-23
GhostStories 2019-10-28
weimasoft 2014-06-30
wuzlun 2016-11-27
人生百态 2017-09-26
binglingnew 2019-06-06
sean0 2019-04-02
yuanyuangugu 2019-07-01
earthhour 2019-06-30
binglingnew 2016-02-16
人生百态 2019-06-28
NSStringlin 2017-09-26