UNPKG

height

Version:

Get the height the element should be

124 lines (110 loc) 3.5 kB
/******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports, __webpack_require__) { var height = __webpack_require__(1) var demo = document.getElementById('demo') var h = height(demo) document.getElementById('height').textContent = h /***/ }, /* 1 */ /***/ function(module, exports, __webpack_require__) { var computedStyle = __webpack_require__(2) /** * Find last visible element * * @param {Element} el * @return {Element} */ function lastVisible(el) { var nodes = el.childNodes for(var i = nodes.length - 1; i >=0; i --) { var node = nodes[i] if (node.nodeType === 1 && computedStyle(node, 'display') !== 'none') { return node } } } function height(node) { var child = lastVisible(node) var pb = parseInt(computedStyle(node, 'paddingBottom'), 10) if (!child) return 0 var mb = parseInt(computedStyle(child, 'marginBottom'), 10) var cb = child.getBoundingClientRect().bottom var r = node.getBoundingClientRect() var res = r.height + (cb - r.bottom) + mb + pb return res } module.exports = height /***/ }, /* 2 */ /***/ function(module, exports) { // DEV: We don't use var but favor parameters since these play nicer with minification function computedStyle(el, prop, getComputedStyle, style) { getComputedStyle = window.getComputedStyle; style = // If we have getComputedStyle getComputedStyle ? // Query it // TODO: From CSS-Query notes, we might need (node, null) for FF getComputedStyle(el) : // Otherwise, we are in IE and use currentStyle el.currentStyle; if (style) { return style [ // Switch to camelCase for CSSOM // DEV: Grabbed from jQuery // https://github.com/jquery/jquery/blob/1.9-stable/src/css.js#L191-L194 // https://github.com/jquery/jquery/blob/1.9-stable/src/core.js#L593-L597 prop.replace(/-(\w)/gi, function (word, letter) { return letter.toUpperCase(); }) ]; } } module.exports = computedStyle; /***/ } /******/ ]); //# sourceMappingURL=bundle.js.map