Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
Upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
surmon-china committed Feb 12, 2020
1 parent a96dc8d commit 38d70fc
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 36 deletions.
50 changes: 30 additions & 20 deletions dist/233333.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,25 @@


_createClass(Emoji233333, [{
key: "preImage",
value: function preImage(url, callback) {
var img = new Image();
img.src = url;
key: "preLoadImage",
value: function preLoadImage(url) {
return new Promise(function (resolve, reject) {
var img = new Image();
img.src = url;

if (img.complete) {
resolve(img);
return;
}

if (img.complete) {
return callback(img);
}
img.onload = function () {
resolve(img);
};

img.onload = function () {
return callback(img);
};
img.onerror = function () {
reject(img);
};
});
} // 启动动画

}, {
Expand Down Expand Up @@ -113,10 +120,10 @@
emojis = this.emojis;

if (!options.emoji) {
throw new Error('缺少 emoji 表情,无法继续!');
return Promise.reject(new Error('未得到有效的 emoji 地址,无法继续!'));
}

this.preImage(options.emoji, function (emj) {
return this.preLoadImage(options.emoji).then(function (emj) {
_this.emojiImg = emj;
var cWidth = parseInt(_this.canvas.style.width);
var count = parseInt(cWidth / (emj.width * options.scale)) * options.density;
Expand Down Expand Up @@ -260,25 +267,28 @@
}, {
key: "launch",
value: function launch() {
var _this2 = this;

if (this.kichikuing) {
return false;
} else {
if (this.options.onStart) {
this.options.onStart();
}

this.createEmojis().then(function () {
if (_this2.options.onStart) {
_this2.options.onStart();
}

this.createEmojis();
this._speed = this.options.speed;
_this2._speed = _this2.options.speed;

this._launch();
}
_this2._launch();
});
} // 更新配置

}, {
key: "update",
value: function update(options) {
if (options) {
this.options = _objectSpread({}, defaultOptions, {}, options);
this.options = _objectSpread({}, this.options, {}, options);
}
} // 获取窗口尺寸

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "emoji-233333",
"version": "0.2.4",
"version": "0.3.0",
"description": "233333",
"main": "dist/233333.js",
"scripts": {
Expand Down
39 changes: 24 additions & 15 deletions src/233333.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ export class Emoji233333 {
}

// 加载图片
preImage(url, callback) {
const img = new Image()
img.src = url
if (img.complete) {
return callback(img)
}
img.onload = () => callback(img)
preLoadImage(url) {
return new Promise((resolve, reject) => {
const img = new Image()
img.src = url
if (img.complete) {
resolve(img)
return
}
img.onload = () => {
resolve(img)
}
img.onerror = () => {
reject(img)
}
})
}

// 启动动画
Expand Down Expand Up @@ -73,11 +81,11 @@ export class Emoji233333 {
// (容器尺寸 / 表情尺寸 / 密度 || 1) = count
const { options, emojis } = this
if (!options.emoji) {
throw new Error('缺少 emoji 表情,无法继续!')
return Promise.reject(new Error('未得到有效的 emoji 地址,无法继续!'))
}

this.preImage(options.emoji, emj => {
this.emojiImg = emj
return this.preLoadImage(options.emoji).then(emj => {
this.emojiImg = emj
const cWidth = parseInt(this.canvas.style.width)
const count = parseInt(cWidth / (emj.width * options.scale)) * options.density
for (let i = 0; i < count; i++) {
Expand Down Expand Up @@ -107,7 +115,7 @@ export class Emoji233333 {
} else if (emojiX > xWidthExtentS) {
targetX = emojiX - (xWidthExtentS * 1.2 * Math.random())
} else {
let random = Math.random()
let random = Math.random()
targetX = random < 0.5 ? xWidthExtentF * random : fullWidth * Math.random()
}
newEmoji.targetX = ~~ (0.5 + targetX)
Expand Down Expand Up @@ -218,21 +226,22 @@ export class Emoji233333 {
launch() {
if (this.kichikuing) {
return false
} else {
}

this.createEmojis().then(() => {
if (this.options.onStart) {
this.options.onStart()
}
this.createEmojis()
this._speed = this.options.speed
this._launch()
}
})
}

// 更新配置
update(options) {
if (options) {
this.options = {
...defaultOptions,
...this.options,
...options
}
}
Expand Down

0 comments on commit 38d70fc

Please sign in to comment.