编写自己的jQuery提示框(Tip)插件

2020-05-23 06:00:53易采站长站整理

                var eLeft = this.element.offset().left,
                    eTop = this.element.offset().top,
                    eWidth = this.element.innerWidth(),
                    eHeight = this.element.innerHeight(),
                    tipw = this.tip[0].offsetWidth,
                    tiph = this.tip[0].offsetHeight,
                    top,
                    left;
                switch(this.options.direction) {
                case ‘top’ :
                    top = eTop – tiph;
                    left = (eLeft – tipw/2) + eWidth/2;
                    this.tip.css({top: top, left: left});
                    break;
                case ‘left’ :
                    top = (eTop – tiph/2) + eHeight/2;
                    left = eLeft – tipw;
                    this.tip.css({top: top, left: left});
                    break;
                case ‘bottom’ :
                    top = eTop + eHeight;
                    left = (eLeft – tipw/2) + eWidth/2;