Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now we're going to be adding in page height detection. This is going to do two things for us; one, it will allow us to take the tooltip container and position it above the cursor, and two, we can make sure that the tooltip doesn't intersect with the top of the browser. So first, let's activate the logo to add a tooltip on to that as well. So let's come back to our index.html file. Let's locate the header element. There is an anchor link in there with a class of logo. Inside of class=logo, let's hit a space and add a second class called tooltip.
Then let's come out after the href attribute, let's add another attribute; data-tip-type=, two quotes, put in text. Another attribute, data-tip-source=, two quotes, and inside there, I'll just put in This is the logo. Now we have our anchor link triggering a tooltip as well.
So if pageY is greater than 100, we know that we're lower on the page than the top 100 pixels. So if that's the case inside of here, we're going to target the tooltip container; dollar sign, parentheses, tick marks inside for a string literal, pound sign, tooltip_container. Outside of the parentheses .css, another set of parentheses, semicolon, inside of the parentheses for CSS, string literal, set the top property.
Outside of the string literal but still inside of the parentheses for CSS, comma, another set of parentheses, plus sign, string literal, px. Now inside of the parentheses, e.pageY-, then another set of parentheses, inside of the parentheses tooltipHeight+20 pixels. So here we're picking out the height of the tooltip container, subtracting that from the pageY and then adding our 20 pixels which will position this above where the cursor hits the actual tooltip item.
And by doing this calculation, we'll make sure that the tooltip height doesn't collide with or cover up the item that's triggering the tooltip. Next, let's come down to the ending bracket, let's add an else, another set of brackets, split that open, and let's come down here and get the previous instruction for the CSS top property. Let's copy that. Let's cut that to the clipboard, let's paste that inside of the else, let's hit File > Save. Let's come back to index.html, choose File > Save All, then File > Preview in Browser.
Inside of the browser, let's hit Reload, rollover our tooltips. You will see that the tooltip now positions above the cursor. The width orientation is still working as well, and then the logo is actually triggering as well, and notice the tooltip for the logo since the cursor is within the first 100 pixels positions underneath of the cursor. Now that we're properly detecting for height and width, next we'll actually hide the tooltip container until you actually roll over one of the tooltips.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97381 Viewers
61 Video lessons · 84625 Viewers
71 Video lessons · 68826 Viewers
56 Video lessons · 101292 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.