Bently
11-19-2007, 07:52 PM
Drop down/ Overlapping Content Script
http://www.dynamicdrive.com/dynamicindex5/overlapcontent.htm
The Issue:
I have the script in a Smarty template. The code works, but the positioning is off. The popup should be directly underneath the image/text I am using as the link. But it pops up in the middle of the page instead of right underneath it.
Can anyone help????
<script type="text/javascript">
{literal}
function getposOffset(overlay, offsettype){
var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
var parentEl=overlay.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}
function overlay(curobj, subobjstr, opt_position){
if (document.getElementById){
var subobj=document.getElementById(subobjstr)
subobj.style.display=(subobj.style.display!="block")? "block" : "none"
var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0)
var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
subobj.style.left=xpos+"px"
subobj.style.top=ypos+"px"
return false
}
else
return true
}
function overlayclose(subobj){
document.getElementById(subobj).style.display="none"
}
{/literal}
</script>
_________
{if $item->getFlags()}
{foreach from=$item->getFlags() item=_flag}
{if $_flag->getImage()}
{assign var=_image value=$_flag->getImage()}
{if $_flag->hasParagraph()}
<a href="#" onclick="return overlay(this, '{$_flag->getName()|escape}_data', 'rightbottom');"><img src="{$_image->getUrl(#flag_image_format#)}" /></a>
<div id="{$_flag->getName()|escape}_data" style="position: absolute; display:none; border: 2px solid black; background-color: white; width: 300px; padding: 3px;"> {$_flag->getParagraph()}
<div align="right"><a href="#" onclick="return overlayclose('{$_flag->getName()|escape}_data');"><b>Close X</b></a></div>
</div>
{else}
<img src="{$_image->getUrl(#flag_image_format#)}" />
{/if}
{/if}
{/foreach}
{/if}
http://www.dynamicdrive.com/dynamicindex5/overlapcontent.htm
The Issue:
I have the script in a Smarty template. The code works, but the positioning is off. The popup should be directly underneath the image/text I am using as the link. But it pops up in the middle of the page instead of right underneath it.
Can anyone help????
<script type="text/javascript">
{literal}
function getposOffset(overlay, offsettype){
var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
var parentEl=overlay.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}
function overlay(curobj, subobjstr, opt_position){
if (document.getElementById){
var subobj=document.getElementById(subobjstr)
subobj.style.display=(subobj.style.display!="block")? "block" : "none"
var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0)
var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
subobj.style.left=xpos+"px"
subobj.style.top=ypos+"px"
return false
}
else
return true
}
function overlayclose(subobj){
document.getElementById(subobj).style.display="none"
}
{/literal}
</script>
_________
{if $item->getFlags()}
{foreach from=$item->getFlags() item=_flag}
{if $_flag->getImage()}
{assign var=_image value=$_flag->getImage()}
{if $_flag->hasParagraph()}
<a href="#" onclick="return overlay(this, '{$_flag->getName()|escape}_data', 'rightbottom');"><img src="{$_image->getUrl(#flag_image_format#)}" /></a>
<div id="{$_flag->getName()|escape}_data" style="position: absolute; display:none; border: 2px solid black; background-color: white; width: 300px; padding: 3px;"> {$_flag->getParagraph()}
<div align="right"><a href="#" onclick="return overlayclose('{$_flag->getName()|escape}_data');"><b>Close X</b></a></div>
</div>
{else}
<img src="{$_image->getUrl(#flag_image_format#)}" />
{/if}
{/if}
{/foreach}
{/if}