diff --git a/package.json b/package.json index 26a994b..27efadb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eruda", - "version": "0.3.3", + "version": "0.3.4", "description": "Console for mobile JavaScript", "main": "dist/eruda.js", "scripts": { diff --git a/src/Elements/Highlight.es6 b/src/Elements/Highlight.es6 index 4d238a1..03c9885 100644 --- a/src/Elements/Highlight.es6 +++ b/src/Elements/Highlight.es6 @@ -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')());