mirror of
https://github.com/liriliri/eruda.git
synced 2026-03-20 09:38:37 +08:00
Fix: Highlight position
This commit is contained in:
@@ -6,7 +6,11 @@ export default class Highlight
|
||||
{
|
||||
constructor($parent)
|
||||
{
|
||||
this._isShow = false;
|
||||
this._top = 0;
|
||||
|
||||
this._appendTpl($parent);
|
||||
this._bindEvent();
|
||||
}
|
||||
setEl(el)
|
||||
{
|
||||
@@ -15,14 +19,16 @@ export default class Highlight
|
||||
}
|
||||
show()
|
||||
{
|
||||
this._calSizeAndPos();
|
||||
this._isShow = true;
|
||||
this.render();
|
||||
this._$el.show();
|
||||
}
|
||||
hide()
|
||||
{
|
||||
this._isShow = false;
|
||||
this._$el.hide();
|
||||
}
|
||||
_calSizeAndPos()
|
||||
render()
|
||||
{
|
||||
var $target = this._$target;
|
||||
|
||||
@@ -33,9 +39,11 @@ export default class Highlight
|
||||
height
|
||||
} = $target.offset();
|
||||
|
||||
this._top = top;
|
||||
|
||||
this._$el.css({
|
||||
left: left,
|
||||
top: top,
|
||||
top: top - window.scrollY,
|
||||
width: width,
|
||||
height: height
|
||||
});
|
||||
@@ -86,6 +94,14 @@ export default class Highlight
|
||||
height: bh - pt - pb
|
||||
});
|
||||
}
|
||||
_bindEvent()
|
||||
{
|
||||
window.addEventListener('scroll', () =>
|
||||
{
|
||||
if (!this._isShow) return;
|
||||
this._$el.css('top', this._top - window.scrollY);
|
||||
}, false);
|
||||
}
|
||||
_appendTpl($parent)
|
||||
{
|
||||
$parent.append(require('./Highlight.hbs')());
|
||||
|
||||
Reference in New Issue
Block a user