/    Sign up×
Community /Pin to ProfileBookmark

Show more opacity in Safari

Hi all,

Please someone who understands Safari behaviour:
The script below gradually shows with more opacity the contents of the div “myDiv” when you put your mouse over it.
And works great for IE and Firefox but does not work for Safari. What can be changed for it to get on well with Safari??
I thought that the way Safari deals with opacity was the same as Firefox’s..

Thanks a zillion in advance!

[CODE]

<head>
<script type=”text/javascript”>

window.onload = init
function init()
{
var d = window.document.getElementById(“myDiv”);
d.className=”gradualshine”;
d.onmouseover=function(){ slowhigh(this); };
d.onmouseout=function(){slowlow(this);};
}

var baseopacity=10

function slowhigh(which2){
imgobj=which2
browserdetect=which2.filters? “ie” : typeof which2.style.MozOpacity==”string”? “mozilla” : “”
instantset(baseopacity)
highlighting=setInterval(“gradualfade(imgobj)”,50)
}

function slowlow(which2){
cleartimer()
instantset(baseopacity)
}

function instantset(degree){
if (browserdetect==”mozilla”)
imgobj.style.MozOpacity=degree/100
else if (browserdetect==”ie”)
imgobj.filters.alpha.opacity=degree
}

function cleartimer(){
if (window.highlighting) clearInterval(highlighting)
}

function gradualfade(cur2){
if (browserdetect==”mozilla” && cur2.style.MozOpacity<1)
cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.1, 0.99)
else if (browserdetect==”ie” && cur2.filters.alpha.opacity<100)
cur2.filters.alpha.opacity+=10
else if (window.highlighting)
clearInterval(highlighting)
}

</script>

<style type=”text/css”>

.gradualshine{
filter:alpha(opacity=30);
-moz-opacity:0.3;
}

#myDiv{
width:200px;
height:200px;
border: 1px solid #be0002;
}

</style>

</head>
<body>

<div id=”myDiv”>
text<br>
<img src=”picture.jpg” border=”0″>
</div>
[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@marcusamiJul 16.2008 — not sure but i think this is browser compatibility

internet explorer

filter:alpha(opacity=93);

firefox & moz

-moz-opacity:.93;

[B]safari & moz;



opacity:.93;[/B]
Copy linkTweet thisAlerts:
@aradadaauthorJul 17.2008 — Thanks so much!! Now it's working great in Safari!

Just one last thing:

For it to work I have to add this to the div: class="gradualshine" onMouseover="slowhigh(this)" onMouseout="slowlow(this)"

So it ends up being [CODE]<div id="myDiv" class="gradualshine" onMouseover="slowhigh(this)" onMouseout="slowlow(this)">[/CODE]
In the code I've posted in my first post, the div is in the same file as the rest of the programming, but "in real life" it is not, the div has to be in a separate file from the rest of the programming (all the files are called and reunited from a main index file).

That's why I'm doing
[CODE]
window.onload = init
function init()
{
var d = window.document.getElementById("myDiv");
d.className="gradualshine";
d.onmouseover=function(){ slowhigh(this); };
d.onmouseout=function(){slowlow(this);};
}
[/CODE]


This function is working super for FireFox but it is not working at all in Internet Explorer and Safari. I know that the whole thing works in Internet Explorer and Safari because I've tried it with the div in the same file, but as soon as the div is in a separate file IE and Safari don't get it.

Any ideas on how to fix the function before so it can work in IE and Safari??

Thanks a million once again!!
Copy linkTweet thisAlerts:
@rnd_meJul 17.2008 — .opacity works in all major browsers except ie.

you no longer have to use the mozopacity setting.
×

Success!

Help @aradada 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.19,
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,
)...