/    Sign up×
Community /Pin to ProfileBookmark

Hidden text with image opacity settings

I am trying to combine two forum scripts into one.

What I want to do is have some links and text that is hidden by an image with the opacity overwriting the information.

I change the opacity with the onmouseover() function and back when moved off image.

I thought changing the z-index would help as well, but no luck yet.

I want to be able to click on the links when the mouse is over the image.

In the script below I am only overwriting a portion of the text & links by shifting
the image right by 50px as a test, but the final version wlll have it set at 0px;

I can click on the link that is outside the image, but not when the opacity is reduced to 25%.

Any ideas how I could change to following?

[code=php]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>DIV menus</title>
<style type=”text/css”>
.Titles {
background-color:cyan;
font-size: 1.5em;
text-decoration: none;
}
.mTitles {
display:none;
background-color:yellow;
width:200px;
}
.makeTransparent {
opacity: 0.25;
/* filter: alpha(opacity=50); */
}
</style>

<script type=”text/javascript”>
// From: http://www.webdeveloper.com/forum/showthread.php?t=189854
// and: http://www.webdeveloper.com/forum/showthread.php?t=190157

function Toggle(Info) {
var CState = document.getElementById(Info).style;
if ((CState.display == “none”) || (CState.display == “”)) { CState.display = “block”; }
else { CState.display = “none”; }
}
function changeOpacity(el) {
el.className = ‘makeTransparent’;
document.getElementById(‘DIVControl’).style.zIndex = 5;
}

function clearCSS(el) {
el.className = ”;
document.getElementById(‘DIVControl’).style.zIndex = 0;
}

</script>
</head>
<body>
<div id=”DIVControl” style=”z-index:0″>

<a href=”#” onclick=”Toggle(‘titleA’)” class=”Titles”>Title A</a> (not a link)<br>
<div id=”titleA” class=”mTitles”>
<a href=”javascript:alert(‘Put link 1 here’)”>Link 1</a> (is a link)<br>
<a href=”javascript:alert(‘Put link 2 here’)”>Link 2</a> (is a link)<br>
<a href=”javascript:alert(‘Put link 3 here’)”>Link 3</a> (is a link)<br>
</div>

<a href=”#” onclick=”Toggle(‘titleB’)” class=”Titles”>Title B</a> (not a link)<br>
<div id=”titleB” class=”mTitles”>
<a href=”javascript:alert(‘Put link 1 here’)”>Link 1</a> (is a link)<br>
<a href=”javascript:alert(‘Put link 2 here’)”>Link 2</a> (is a link)<br>
<a href=”javascript:alert(‘Put link 3 here’)”>Link 3</a> (is a link)<br>
</div>

Text before…
</div>

<div style=”position:absolute;top:0px;left:50px”> <!– final version will have left:0px instead –>
<img src=”http://www.lastpersonwins.com/pixel/uploaded_img/funny%20face.jpg”
onmouseover=”changeOpacity(this)” onmouseout=”clearCSS(this)”/>
</div>
Text after…

</body>
</html>
[/code]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@DokAug 31.2008 — You can only change z-index for elements which are positioned relative or absolute so you need something like
[CODE]<div id="DIVControl" style="z-index:0; [COLOR="Red"]position:relative;[/COLOR]">[/CODE]
but when you change the z-index of the div control the image will fire a mouseout reverting the z-index which will in turn fire a mouseover and so on. So you need to change the script in order to avoid an endless series of mouseover/mouseout.
Copy linkTweet thisAlerts:
@JMRKERauthorSep 01.2008 — @Dok, you were right.

I added the 'position:relative' and the image flickered madly when in the overlapping area.

I took out the z-index logic and it now does as before, which is nothing other than make the image less opaque..

So you need to change the script in order to avoid an endless series of mouseover/mouseout.[/QUOTE]
Any other ideas on where to change the script to obtain the desired effect, which is:

To have the underlying links/text obscured until the mouse is over the image

at which time the image becomes less opaque and you could then click on the revealed links.
Copy linkTweet thisAlerts:
@DokSep 01.2008 — This can only be done by changing the zIndex as you are doing so the solution will have to be to stop the flickering. This example is not perfect but it shows how you might do it
[code=html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>WebDev Test</title>

<style type="text/css">

#div1 {
position: absolute;
width: 200px;
height: 200px;
border: 1px solid #000;
}

#div2 {
position: absolute;
width: 200px;
height: 200px;
top: 100px;
left: 100px;
background: #f00;
}

</style>

<script type="text/javascript" charset="utf-8">

function main() {
document.getElementById('div1').onmouseout = mOut;
document.getElementById('div2').onmouseover = mOver;
}

function mOver(e) {
document.getElementById('div1').style.zIndex = 1;
document.getElementById('div2').style.zIndex = 0;
document.getElementById('div2').style.opacity = 0.25;
}

function mOut(e) {
document.getElementById('div1').style.zIndex = 0;
document.getElementById('div2').style.zIndex = 1;
document.getElementById('div2').style.opacity = 1;
}

</script>
</head>
<body onload="main();">
<div id="div1">
<a href="#">Here is the link - a link is here</a><br />
<a href="#">Here is the link - a link is here</a><br />
<a href="#">Here is the link - a link is here</a><br />
<a href="#">Here is the link - a link is here</a><br />
<a href="#">Here is the link - a link is here</a><br />
<a href="#">Here is the link - a link is here</a><br />
<a href="#">Here is the link - a link is here</a><br />
<a href="#">Here is the link - a link is here</a><br />
<a href="#">Here is the link - a link is here</a>
</div>
<div id="div2">

</div>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@JMRKERauthorSep 01.2008 — @Dok,

Thank you. Gives a LOT less flicker than my attempt.

I think it may have possibilities if the whole underlying area is not filled with links.

Appreciate the confirmation that at least I was headed in the right direction. ?
×

Success!

Help @JMRKER 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 4.29,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...