![]()
Snippets of A |
|
|
What are snippets? |
|
function detectOverflow(e/*||null*/, hostObj, clientObj, clientOriginalY/*||0*/, clientOriginalX/*||0*/, strictBoundaries, andReposition){//2.0.0.0 if(e){clientOriginalY=e.pageY; clientOriginalX=e.pageX;}; if(typeof event != 'undefined'){clientOriginalY=event.clientY+document.body.scrollTop; clientOriginalX=event.clientX+document.body.scrollLeft;} if(window['getComputedStyle']){ if(getComputedStyle(hostObj, null).getPropertyValue('display')){hostObj.style.display='block';/*or wrong computing*/}; if(getComputedStyle(clientObj, null).getPropertyValue('display')){clientObj.style.display='block';/*or wrong computing*/}; } else{ if(hostObj.currentStyle['display']){hostObj.style.display='block';/*or wrong computing*/}; if(clientObj.currentStyle['display']){clientObj.style.display='block';/*or wrong computing*/}; } var clientVerticalPos=clientOriginalY+clientObj.offsetHeight, clientHorizontalPos=clientOriginalX+clientObj.offsetWidth; var hostVerticalPos=hostObj.offsetTop+hostObj.offsetHeight, hostHorizontalPos=hostObj.offsetLeft+hostObj.offsetWidth; var toReturn= (strictBoundaries)?[ /******* A C C O U N T F O R H O S T B O U N D A R I E S (border, scrollbars): *******/ /*** V E R T I C A L W I S E: ***/ /*topwise overflow*/(clientOriginalY>=hostObj.offsetTop && clientOriginalY<hostObj.offsetTop+parseInt((window['getComputedStyle'])?getComputedStyle(hostObj, null).getPropertyValue('border-top-width'):hostObj.currentStyle['border-top-width']))? hostObj.offsetTop+parseInt((window['getComputedStyle'])?getComputedStyle(hostObj, null).getPropertyValue('border-top-width'):hostObj.currentStyle['border-top-width']) : /*bottomwise overflow*/(clientOriginalY+clientObj.clientHeight>hostObj.offsetTop+hostObj.clientHeight+parseInt((window['getComputedStyle'])?getComputedStyle(hostObj, null).getPropertyValue('border-bottom-width'):hostObj.currentStyle['border-bottom-width']))? clientOriginalY+((hostVerticalPos-(hostObj.offsetHeight-hostObj.clientHeight)) - clientVerticalPos + parseInt((window['getComputedStyle'])?getComputedStyle(hostObj, null).getPropertyValue('border-bottom-width'):hostObj.currentStyle['border-bottom-width'])) : /*no verticalwise overflow*/clientOriginalY /*** H O R I Z O N T A L W I S E: ***/ , /*leftwise overflow*/(clientOriginalX>=hostObj.offsetLeft && clientOriginalX<hostObj.offsetLeft+parseInt((window['getComputedStyle'])?getComputedStyle(hostObj, null).getPropertyValue('border-left-width'):hostObj.currentStyle['border-left-width']))? hostObj.offsetLeft+parseInt((window['getComputedStyle'])?getComputedStyle(hostObj, null).getPropertyValue('border-left-width'):hostObj.currentStyle['border-left-width']) : /*rightwise overflow*/(clientOriginalX+clientObj.clientWidth>=hostObj.offsetLeft+hostObj.clientWidth+parseInt((window['getComputedStyle'])?getComputedStyle(hostObj, null).getPropertyValue('border-right-width'):hostObj.currentStyle['border-right-width']))? clientOriginalX+((hostHorizontalPos-(hostObj.offsetWidth-hostObj.clientWidth)) - clientHorizontalPos + parseInt((window['getComputedStyle'])?getComputedStyle(hostObj, null).getPropertyValue('border-right-width'):hostObj.currentStyle['border-right-width'])) : /*no horizontalwise overflow*/clientOriginalX ] /******* D O N O T A C C O U N T F O R H O S T B O U N D A R I E S: *******/ : [ (hostVerticalPos - clientVerticalPos)<0 ? /*verticalwise overflow*/clientOriginalY+(hostVerticalPos - clientVerticalPos) : /*no verticalwise overflow*/clientOriginalY , (hostHorizontalPos - clientHorizontalPos)<0 ? /*horizontalwise overflow*/clientOriginalX+(hostHorizontalPos - clientHorizontalPos) : /*no horizontalwise overflow*/clientOriginalX ]; if(andReposition){clientObj.style.display='block'; clientObj.style.top=toReturn[0]+'px'; clientObj.style.left=toReturn[1]+'px';}; return toReturn; /*keep this comment to reuse freely http://www.fullposter.com/?1*/}Remove colors
event or passed as null or boolean false: this argument if passed represents the coordinates of the mouse upn the event that has called the function.
getElementById).getElementById).parseInt() applied to it, for good safety measure.parseInt() applied to it, for good safety measure.true or false. If true, the strict boundaries mode will be applied (that is, the client layer's edges must not trespass the host's scrollbars and borders too, if any.
false if the host is the whole document or the body.true, it will also reposition the client layer.display:block) to ensure browsers won't meet problems calculating the correct offsets.
<h3>Scroll, find the red layer and click on it.</h3> <div id="client" style="display:none; position:absolute;z-index:10;width:30px; height:30px; background-color:#0000ff;"></div> The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog <div id="host" style="position:absolute; top:900px; left:30px;overflow:auto; width:150px; height:100px;background-color:#ff0000; padding:20px; margin:25px; border:#000000 20px double;"> The quick brown fox<br />jumpsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog</div> <br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog<br />The quick brown fox<br />jumps over<br />the lazy dog <script> //place your function here, then: /*on a layer*/ document.getElementById('host').onmouseup=function(event){ detectOverflow(event, document.getElementById('host'), document.getElementById('client'), 0, 0, true, true); } /*or, but comment out above: on page: document.onmouseup=function(event){ detectOverflow(event, document.documentElement, document.getElementById('client'), 0, 0, true, true); } */ </script>Remove colors