![]() |
Web Development »
Client side scripting »
General
Intermediate
A Javascript Scrolling PopupBy Massimo BeatiniWith this script you can build scrolling popups for your web pages choosing display corner and scrolling direction. |
Javascript, Windows, Visual Studio, Dev
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

This script allow you to build a scrolling pop up using divs. You can locate the scrolling pop up in a corner of a web page and choose the scrolling direction (i.e. left-to-right or top-down) This script has been tested only with Internet Explorer 6.0, Firefox 1.0.7 and Opera 8.51 on Windows 2003 Server.
buildPopup_HtmlCode
//
// buildPopup_HtmlCode
// build popup passing it the html code to put inside
//
function buildPopup_HtmlCode(width, height, title, htmlCode)
{
if (width)
popupWidth = width;
if (height)
popupHeight = height;
if (title)
_title = title
document.write('<div id="postit" class="postit">');
document.write('<div id="postit_title" class="title"><b>' + _title +
'<span class="spantitle"><img src="close.gif" border="0" ' +
'title="Close" align="right" WIDTH="11" HEIGHT="11" onclick="closeit()"> </b></span></div>');
document.write('<div id="postit_content" class="content">');
document.write(htmlCode);
document.write('</div></div>');
getCrossObj();
}
or specify a the url of a frame to show inside using the function buildPopup_Frame
//
// buildPopup_Frame
// passing it the url of the frame to display inside
//
function buildPopup_Frame(width, height, title, framesrc)
{
if (width)
popupWidth = width;
if (height)
popupHeight = height;
if (title)
_title = title
document.write('<div id="postit" class="postit" >');
document.write('<div id="postit_title" class="title"><b>' + _title + ' <span class="spantitle"><img src="close.gif" border="0" ' +
'title="Close" align="right" WIDTH="11" HEIGHT="11" onclick="closeit()"> </b></span></div>');
document.write('<div id="postit_content" class="content">');
document.write('<iframe src="' + framesrc + '" width="100%" height="100%" marginwidth="0" marginheight="0" ' +
'hspace="0" vspace="0" frameborder="0" scrolling="no" bordercolor="#000000"></iframe>');
document.write('</div></div>');
getCrossObj();
}
The building function also accepts width, height and title parameters to characterize your pop up.
scrolling_popup.css file.
Then you have to call one of the two building functions
At this point you have to choose when to show your pop up calling the function ShowTheBox
This function accepts 5 input parameters:
leftSide or rightSide;
bottomCorner or topCorner;
leftRight or rightLeft or bottopUp or topDown;
Senseless combination of the side, corner and direction parameters will not produce any result.ShowTheBox(true, leftSide, topCorner, rightLeft); has a senseless combination:rightLeft direction on the leftSide means hide the pop up beyond the
left page's border.
//
// ShowTheBox
//
function ShowTheBox(only_once, side, corner, direction)
{
if (side == leftSide)
{
if (direction == rightLeft)
return;
crossobj.style.left = '1px';
}
else
{
if (direction == leftRight)
return;
crossobj.style.right = '1px';
}
if ((corner == topCorner) && (direction == bottopUp))
return;
if ((corner == bottomCorner) && (direction == topDown))
return;
if ( (direction == topDown) && (corner == topCorner) )
crossobj.style.top = '-' + popupHeight + 'px';
else if ( ((direction == rightLeft)||(direction == leftRight)) && (corner == topCorner) )
crossobj.style.top = '1px';
else if (corner == bottomCorner)
crossobj.style.bottom = '2px';
if (only_once)
only_once_per_browser = only_once;
if (only_once_per_browser)
{
// verify the presence of a cookie
if (showOrNot())
showIt(direction);
}
else
setTimeout("showIt("+ direction + ")",1030);
}

ShowTheBox calling example
<script type="text/javascript">
ShowTheBox(false, leftSide, bottomCorner, bottopUp);
</script>
If the only_once parameter is true the script checks the presence of a specified cookie.
//
// check the cookie
//
function showOrNot(direction)
{
var showit = false;
if (get_cookie('postTheBoxDisplay')=='')
{
showit = true;
document.cookie = "postTheBoxDisplay=yes";
}
return showit;
}
Zip Souce file contains script, css, images and demo html pages.
I hope you enjoy this article.
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 14 Feb 2006 Editor: |
Copyright 2006 by Massimo Beatini Everything else Copyright © CodeProject, 1999-2009 Web12 | Advertise on the Code Project |