ionic学习笔记

获取元素文字边界信息

/**
 * @ngdoc method
 * @name ionic.DomUtil#getTextBounds
 * @description
 * Get a rect representing the bounds of the given textNode.
 * @param {DOMElement} textNode The textNode to find the bounds of.
 * @returns {object} An object representing the bounds of the node. Properties:
 *   - `{number}` `left` The left positton of the textNode.
 *   - `{number}` `right` The right positton of the textNode.
 *   - `{number}` `top` The top positton of the textNode.
 *   - `{number}` `bottom` The bottom position of the textNode.
 *   - `{number}` `width` The width of the textNode.
 *   - `{number}` `height` The height of the textNode.
 */
getTextBounds: function(textNode) {
    if(document.createRange) {
        var range = document.createRange();
        range.selectNodeContents(textNode);
        if(range.getBoundingClientRect) {
            var rect = range.getBoundingClientRect();
            if(rect) {
                var sx = window.scrollX;
                var sy = window.scrollY;

                return {
                     top: rect.top + sy,
                     left: rect.left + sx,
                     right: rect.left + sx + rect.width,
                     bottom: rect.top + sy + rect.height,
                     width: rect.width,
                     height: rect.height
                };
            }
        }
    }
    return null;
},

自定义事件

ionic.CustomEvent = (function() {
        if( typeof window.CustomEvent === 'function' ) return CustomEvent;

        var customEvent = function(event, params) {
        var evt;
        params = params || {
            bubbles: false,
            cancelable: false,
            detail: undefined
            };
            try {
            evt = document.createEvent("CustomEvent");
            evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
            } catch (error) {
            // fallback for browsers that don't support createEvent('CustomEvent')
            evt = document.createEvent("Event");
            for (var param in params) {
            evt[param] = params[param];
            }
            evt.initEvent(event, params.bubbles, params.cancelable);
            }
            return evt;
            };
            customEvent.prototype = window.Event.prototype;
            return customEvent;
            })();

判断对象是否存在某个key

  ionic.Gestures.HAS_TOUCHEVENTS = ('ontouchstart' in window);

判断是否是移动端的正则

  ionic.Gestures.MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android|silk/i;
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇