Page 1 of 1

[solved] how to get the hight of a tip element

PostPosted: Sun Mar 07, 2010 4:33 pm
by hamburger
Hello,
i'am trying to get the high of the tip element to adjust the offset. How to do that?
Where I have to place the this.getHight()?

My code:
  1.  var Hint = new Tips($$('.poptip'), {
  2.    showDelay: 500,    //default is 100
  3.    hideDelay: 100,   //default is 100
  4.    offset: {
  5.         'x': 40,       //I would like to adjust this in dependency of the width or hight of the tip element
  6.         'y': -110      //not static
  7.     },
  8.    fixed: false,      //default is false
  9.    className: 'test_tip', //default is .tip-wrap.
  10.    onShow: function(tip,el) {
  11.     tip.fade('in');
  12.    },
  13.    onHide: function(tip,el) {
  14.     tip.fade('out');
  15.    }
  16.   });

Re: how to get the hight of a tip element

PostPosted: Sat Mar 13, 2010 1:26 pm
by rollbich
Hi !

Well, I'm afraid you can't do this like that because the tip is created on the fly.
So you have to modified the 'position function' in the mootools tips class in the 'mootools.more' file to get access to the height of the tip.
In the position function, the height of the tip is given by this.tip.offsetHeight
In this exemple, I added the height of the tip divided by 3 to the x offset.

  1.  
  2. position: function(event){
  3.         var size = window.getSize(), scroll = window.getScroll();
  4.         var tip = {x: this.tip.offsetWidth, y: this.tip.offsetHeight};
  5.         var props = {x: 'left', y: 'top'};
  6.         for (var z in props){
  7.             var offs = 0;  
  8.             if (z == 'x') offsh = this.tip.offsetHeight;
  9.             var pos = event.page[z] + this.options.offsets[z] + parseInt(offsh/3);
  10.             if ((pos + tip[z] - scroll[z]) > size[z]) pos = event.page[z] - this.options.offsets[z] - tip[z] - parseInt(offsh/3) ;
  11.             this.tip.setStyle(props[z], pos);
  12.         }
  13.     },
  14.  

Re: how to get the hight of a tip element

PostPosted: Mon Mar 15, 2010 5:50 pm
by hamburger
Hello rollbich,
tanks for your solution.
I'am not a mooProfessional so i need some time to look into what you recomended.
I'am thinking in a solution with the onShow-function like:

  1. onShow: function(tip,el) {
  2.    var coords = tip.getCoordinates(), t = tip.getSize(), styles =
  3. {opacity: 0};
  4.    styles.left = coords.left + (coords.width / 2).round() - (t.x /
  5. 2).round();
  6.    styles.top = coords.top - 20 - t.y;
  7.    tip.setStyles(styles);
  8.    tip.fade('in');
  9.    },
  10.  

but at the moment without success

Re: how to get the hight of a tip element

PostPosted: Tue Mar 16, 2010 1:15 pm
by ghazal
@hamburger,
I guess you are busy, but A. Newton gave you a detailed solution on googlegroups and it'd be nice to share it here, as you opened this thread.
It might be helpful to everyone.
Among the advices he gave, there is this measure stuff:
http://mootools.net/search/?search=1&query=measure
of which, I, personnally had no idea

-1st advice :
"ok. so the problem here is that Tips.js calls your show option *before* it
positions the tip. This is because the tip is hidden, so it waits for you to
show it and then positions it."
I noticed it because I always have this pb : position correctly a call

-2nd
"change the offset option dynamically"--> this is precious.

A. Newton's Mooshell solution:
http://mootools.net/shell/Swat4/2/

Generally speaking, both threads where very helpful to me because the Tooltip thingy in Moo1.2.4 isn't that obvious, and I thank you for this.

Cheers.

[solved] how to get the hight of a tip element

PostPosted: Tue Mar 16, 2010 4:39 pm
by hamburger
Hello, here is the code i'am using:

  1. var Hint = new Tips($$('.poptip'), {
  2.    showDelay: 300,    //default is 100
  3.    hideDelay: 500,   //default is 100
  4.    offset: {          
  5.        'x': 40,       //default is 16    
  6.         'y': -110        //default is 16
  7.     },
  8.    fixed: true,      //default is false
  9.    className: 'my_tip', //default is .tip-wrap.
  10.    onShow: function(tip,el) {
  11.        tip.measure(function(){  //measure because its display:none;  
  12.            var t = tip.getSize();
  13.            this.setOptions({
  14.                offset: {
  15.                    x: 35,
  16.                    y: 35 - t.y
  17.                }
  18.            });
  19.        }.bind(this));
  20.        tip.fade('in');
  21.    },
  22.    onHide: function(tip,el) {
  23.     tip.fade('out');
  24.    }
  25.   });


thx for help to Aaron Newton on http://groups.google.com/group/mootools-users/