From a971c2146012a6a3cc2d4bf5fbc9fbf78c10c204 Mon Sep 17 00:00:00 2001 From: wangxueliang Date: Fri, 3 Nov 2017 17:10:38 +0800 Subject: [PATCH] add rate demo --- components/rate/demo/rate.vue | 71 +++++++++++++++++++++++++++++++++++ components/util/util.js | 49 ++++++++++++------------ 2 files changed, 95 insertions(+), 25 deletions(-) create mode 100644 components/rate/demo/rate.vue diff --git a/components/rate/demo/rate.vue b/components/rate/demo/rate.vue new file mode 100644 index 000000000..31f3a2fe3 --- /dev/null +++ b/components/rate/demo/rate.vue @@ -0,0 +1,71 @@ + + diff --git a/components/util/util.js b/components/util/util.js index 6d0070323..bef8da463 100644 --- a/components/util/util.js +++ b/components/util/util.js @@ -1,40 +1,39 @@ -function getScroll(w, top) { - let ret = top ? w.pageYOffset : w.pageXOffset; - const method = top ? 'scrollTop' : 'scrollLeft'; +function getScroll (w, top) { + let ret = top ? w.pageYOffset : w.pageXOffset + const method = top ? 'scrollTop' : 'scrollLeft' if (typeof ret !== 'number') { - const d = w.document; + const d = w.document // ie6,7,8 standard mode - ret = d.documentElement[method]; + ret = d.documentElement[method] if (typeof ret !== 'number') { // quirks mode - ret = d.body[method]; + ret = d.body[method] } } - return ret; + return ret } -function getClientPosition(elem) { - let box; - let x; - let y; - const doc = elem.ownerDocument; - const body = doc.body; - const docElem = doc && doc.documentElement; - box = elem.getBoundingClientRect(); - x = box.left; - y = box.top; - x -= docElem.clientLeft || body.clientLeft || 0; - y -= docElem.clientTop || body.clientTop || 0; +function getClientPosition (elem) { + let x + let y + const doc = elem.ownerDocument + const body = doc.body + const docElem = doc && doc.documentElement + const box = elem.getBoundingClientRect() + x = box.left + y = box.top + x -= docElem.clientLeft || body.clientLeft || 0 + y -= docElem.clientTop || body.clientTop || 0 return { left: x, top: y, - }; + } } export const getOffsetLeft = (el) => { - const pos = getClientPosition(el); - const doc = el.ownerDocument; - const w = doc.defaultView || doc.parentWindow; - pos.left += getScroll(w); - return pos.left; + const pos = getClientPosition(el) + const doc = el.ownerDocument + const w = doc.defaultView || doc.parentWindow + pos.left += getScroll(w) + return pos.left }