Skip to content

Commit

Permalink
✨支持在长按鼠标右键时显示大图,对动图进行缩放
Browse files Browse the repository at this point in the history
  • Loading branch information
xuejianxianzun committed Aug 12, 2023
1 parent 3ce5615 commit bf60c28
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ if (!check) {

至此问题完美解决。

### ✨支持在长按鼠标右键时显示大图,对动图进行缩放

右键预览大图时可以通过鼠标滚轮来缩放画布尺寸。但是我发现动画不会随画布尺寸变化,现在进行了完善。

### ✨新增了 Input 组件

通过引入 `Input.ts` 可以在页面上显示一个输入框(input 或者 textarea),并且可以通过一些选项进行配置,以接收用户的输入。
Expand All @@ -128,6 +132,8 @@ if (!check) {

不过目前在主分支里并没有实际使用它。

### 🕑更新了作品发布时间数据

## 16.1.2 2023/08/11

### 🐛修复了“显示更大的缩略图”的一些问题
Expand Down
13 changes: 13 additions & 0 deletions dist/js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -8856,6 +8856,17 @@ class PreviewUgoira {
this.canvas.width = this.width;
this.canvas.height = this.height;
}
setSize(width, height) {
// 当用户移动鼠标时,ShowOriginSizeImage 会频繁触发 setSize
// 如果频繁的重设尺寸,会导致动画闪烁。所以判断只在有必要时才重设尺寸
if (width === this.width && height === this.height) {
return;
}
this.width = width;
this.height = height;
this.canvas.width = this.width;
this.canvas.height = this.height;
}
destroy() {
this.destroyed = true;
window.cancelAnimationFrame(this.animationID);
Expand Down Expand Up @@ -11170,6 +11181,8 @@ class ShowOriginSizeImage {
this.wrap.style.height = this.style.height + 'px';
this.wrap.style.marginTop = this.style.mt + 'px';
this.wrap.style.marginLeft = this.style.ml + 'px';
this.previewUgoira &&
this.previewUgoira.setSize(this.style.width, this.style.height);
}
setData(urls, data, index) {
this.urls = urls;
Expand Down
2 changes: 1 addition & 1 deletion dist/js/content.js.map

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/ts/PreviewUgoira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,19 @@ class PreviewUgoira {
this.animationID = window.requestAnimationFrame(this.play)
}

public setSize(width: number, height: number) {
// 当用户移动鼠标时,ShowOriginSizeImage 会频繁触发 setSize
// 如果频繁的重设尺寸,会导致动画闪烁。所以判断只在有必要时才重设尺寸
if (width === this.width && height === this.height) {
return
}

this.width = width
this.height = height
this.canvas.width = this.width
this.canvas.height = this.height
}

public destroy() {
this.destroyed = true
window.cancelAnimationFrame(this.animationID)
Expand Down
3 changes: 3 additions & 0 deletions src/ts/ShowOriginSizeImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ class ShowOriginSizeImage {
this.wrap.style.height = this.style.height + 'px'
this.wrap.style.marginTop = this.style.mt + 'px'
this.wrap.style.marginLeft = this.style.ml + 'px'

this.previewUgoira &&
this.previewUgoira.setSize(this.style.width, this.style.height)
}

public setData(urls: Urls, data: ArtworkData, index: number) {
Expand Down

0 comments on commit bf60c28

Please sign in to comment.