Fix: Highlight position

This commit is contained in:
surunzi
2016-05-12 19:30:43 +08:00
parent 8193d4b78f
commit fe9c97e41f
2 changed files with 20 additions and 4 deletions

View File

@@ -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')());