/    Sign up×
Community /Pin to ProfileBookmark

Image always on the middle of the page

Hi
I have a image that need to be always on the middle of the page and i will have a long scroll on this page, so thwe image must move to the middle as i scroll down or up .

how can it be done ?

<SPAN id=MinMax style=”CURSOR: hand;” onclick=”return MinMax_Click();”>
<IMG SRC=”img.gif” WIDTH=”7″ HEIGHT=”13″ BORDER=”0″ id=middleimg>
</SPAN>
Thank´s in advance

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@James_GatkaApr 12.2006 — [CODE]<html>
<head>
<script type="text/javascript">

var useWidth = "200"; // this is the width of the image;
var useHeight = "160"; // this is its height;
var useFloat = "";
var xV = 0;
var xL = 0;

function stayHome(){

var nV = 0;
var nL = 0;
if(!document.body.scrollTop)
{
nV = document.documentElement.scrollTop;
nL = document.documentElement.scrollLeft;
}
else {
nV = document.body.scrollTop;
nL = document.body.scrollLeft;
}
if (nV == 0){window.scrollBy(0,1)}
useFloat.style.top = nV+xV+"px";
useFloat.style.left = nL+xL+"px";
setTimeout("stayHome()",50);
}

function init(){

document.getElementById('isFloat').style.width = useWidth;
useFloat = document.getElementById('isFloat');
useFloat.style.left = ((screen.width-30)/2)-(useWidth/2)+"px";
if(!document.body.scrollTop)
{useFloat.style.top = (document.documentElement.clientHeight/2)-(useHeight/2)+"px"}
if (useFloat.style.top == "" || parseInt(useFloat.style.top) < 0 || parseInt(useFloat.style.top) > 400)
{useFloat.style.top = (document.body.clientHeight/2)-(useHeight/2)+"px"}
xV = useFloat.offsetTop;
xL = useFloat.offsetLeft;
stayHome();

}

onload=init;

</script>
</head>
<body>
<table height='1300' width='1000'>
<tbody>
<td>

<div id='isFloat' style='position:absolute;overflow:hidden;height:auto;border:solid black 1px;font-size:14pt;background-color:lightyellow;color:darkblue;text-align:center'>
<div style='padding:3px'><img src='images/floatingImg.jpg'></div>

</div>
</td>
</tbody>
</table>
</body>
</html>[/CODE]
Copy linkTweet thisAlerts:
@amrigoauthorApr 12.2006 — Thank´s ! can i put the image inside a cell table? it does not impact on the script ?

Best regards
Copy linkTweet thisAlerts:
@amrigoauthorApr 12.2006 — i have a form named frm how can i put the image inside a table cell inside this form and the script works?
Copy linkTweet thisAlerts:
@James_GatkaApr 12.2006 — Just put all this:

[CODE]<div id='isFloat' style='position:absolute;overflow:hidden;height:auto;border:solid black 1px;font-size:14pt;background-color:lightyellow;color:darkblue;text-align:center'>
<div style='padding:3px'><img src='images/floatingImg.jpg'></div>

</div>[/CODE]
in the table cell.
×

Success!

Help @amrigo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...