<?xml version="1.0" encoding="UTF-8"?>
<post>
  <body>This should work. I rewrote the code so we don't have to worry about scroll distance.
&lt;pre&gt;
tip.setAttribute('style', 'display: none; position:fixed; border:1px solid #AAA; background-color:#FFF');
&lt;/pre&gt;
&lt;pre&gt;
        const TIP_X_OFFSET = 45, TIP_Y_OFFSET = 120, FLIPPER = 400;
        const tip = document.getElementById('bw-tooltip');
        const tip_height = tip.offsetHeight;
	const tip_width = tip.offsetWidth;
        const mouseY = event.clientY;
	const mouseX = event.clientX;
        const tip_abs_bottom = mouseY - TIP_Y_OFFSET + tip_height;
        const screen_height = document.body.clientHeight;
	const screen_width = document.body.clientWidth;

        tip.style.top = mouseY &lt; TIP_Y_OFFSET || tip_height &gt; screen_height ? 0 :
        tip_abs_bottom &gt; screen_height ? screen_height - tip_height : mouseY - TIP_Y_OFFSET + 'px';

	tip.style.right = '';
	if(mouseX &gt; screen_width - FLIPPER){
		tip.style.left = '';
		tip.style.right = screen_width + TIP_X_OFFSET - mouseX + 'px';}
	else{
	        tip.style.left = mouseX + TIP_X_OFFSET + 'px';}
&lt;/pre&gt;</body>
  <body-html>&lt;p&gt;This should work. I rewrote the code so we don't have to worry about scroll distance.
&lt;br /&gt;&lt;pre&gt;
tip.setAttribute('style', 'display: none; position:fixed; border:1px solid #AAA; background-color:#FFF');
&lt;/pre&gt;&lt;pre&gt;
        const TIP_X_OFFSET = 45, TIP_Y_OFFSET = 120, FLIPPER = 400;
        const tip = document.getElementById('bw-tooltip');
        const tip_height = tip.offsetHeight;
	const tip_width = tip.offsetWidth;
        const mouseY = event.clientY;
	const mouseX = event.clientX;
        const tip_abs_bottom = mouseY - TIP_Y_OFFSET + tip_height;
        const screen_height = document.body.clientHeight;
	const screen_width = document.body.clientWidth;

        tip.style.top = mouseY &amp;lt; TIP_Y_OFFSET || tip_height &gt; screen_height ? 0 :
        tip_abs_bottom &gt; screen_height ? screen_height - tip_height : mouseY - TIP_Y_OFFSET + 'px';

	tip.style.right = '';
	if(mouseX &gt; screen_width - FLIPPER){
		tip.style.left = '';
		tip.style.right = screen_width + TIP_X_OFFSET - mouseX + 'px';}
	else{
	        tip.style.left = mouseX + TIP_X_OFFSET + 'px';}
&lt;/pre&gt;&lt;/p&gt;</body-html>
  <created-at type="datetime">2009-03-02T02:15:44Z</created-at>
  <forumable-id type="integer">39393</forumable-id>
  <forumable-type>Script</forumable-type>
  <id type="integer">99389</id>
  <topic-id type="integer">21519</topic-id>
  <updated-at type="datetime">2009-03-02T06:34:19Z</updated-at>
  <user-agent nil="true"></user-agent>
  <user-id type="integer">64431</user-id>
</post>
