Comments (2)
from pttchrome.
#40 與 #55 初步闡述了該問題發生的原理。以下對其進一步分析。
#55 指出該問題位於函式 getTop()
。
PttChrome/src/components/ImagePreviewer.js
Lines 80 to 92 in 7f2d668
(相關的參數 left
與 top
應該會是游標的位置,故以下如此假設)
目前的圖片位置邏輯是:
- 水平位置固定在游標右方 30 CSS 像素處。(爲何不定義
getLeft()
?) - 垂直位置則以
getTop()
函式求出:if (top + height / 2 > pageHeight - 20) {
「如果頁尾底上方 20 CSS 像素處到游標處之間的空間無法容下圖片的一半原始高度的話」……if (height / 2 < top) { return pageHeight - 20 - height; }
「如果頁首頂到 游標處 之間的空間容得下圖片的 一半原始高度 的話,就以頁尾底上方 20 CSS 像素處爲 原始圖片底端 顯示圖片」(虫舍?)- 理應檢査的是頁首頂到頁尾底間的空間容不容得下整個圖片。
- 如果圖片已被縮小,那實際的圖片底端就會落在原始圖片底端的上方,且愈縮愈嚴重。
- (
else { return 20; }
)
(「否則的話以頁首頂下方 20 CSS 像素處爲圖片頂端顯示圖片」)
} else if (top - 20 > height / 2) { return top - height / 2; }
「如果容得下,且頁首頂下方 20 CSS 像素處到游標處之間的空間也容得下圖片的一半原始高度的話,就以游標位置爲原始圖片中心顯示圖片」return 20;
「否則的話,以頁首頂下方 20 CSS 像素處爲圖片頂端顯示圖片」
#40 提到,目前的計算方式 (實際上是 getTop()
) 是使用圖片未經縮放的原始尺寸計算,如果圖片縮小的話會算錯以圖片中心或底端爲基準時的位置。
雖然我不是邏輯學家,但這看起來很複雜對吧?
它的理念是讓圖片中心橫軸對齊游標,但以不超出頁緣減 20 CSS 像素的界線爲前提。
但我有個更簡單的方案:
const getTop = (top, height) => {
const pageHeight = $(window).height();
height = min(0.8 * pageHeight, height); // 可能有些許誤差,先暫時忽略
return max(20, min(pageHeight - 20 - height, top - height / 2));
};
from pttchrome.
Related Issues (20)
- Ubuntu 18.04/Linux MINT 19 + Chrome + fcitx 無法正常中文輸入 HOT 2
- 熱訊(水球)的偵測有時會失敗
- 「輸入小幫手」的下拉式選單超出小幫手視窗時,顯示怪異
- macOS 倉頡輸入法輸入「:」會進到說明頁 HOT 1
- 好讀模式 捲動軸會擋到最右邊的字
- 驗證碼頁面的右鍵貼上選項失效 (Firefox 62.0)
- 右鍵貼上造成網頁卡死 HOT 1
- 好讀模式 開不了pbs.twimg.com的圖
- Typo
- 用思源黑體有些字會被擋住 HOT 5
- ^W 熱鍵和瀏覽器的快捷鍵衝突 HOT 1
- Mac 鍵盤使用 Safari 13.0.3 (macOS 10.14.6) 無法貼上 HOT 1
- 和瀏覽器的密碼管理員整合 HOT 2
- linux下輸入法會抓不到游標位置
- 閒置斷線 HOT 7
- 解析水球的正則表示式的呈現方式問題 HOT 2
- 進行水球通知時檢查權限並且要求權限
- 在Chrome開啟沒有自動登入選項 HOT 2
- Live文小幫手失效 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pttchrome.