www.webdeveloper.com
Results 1 to 2 of 2

Thread: Reading value of elements opacity

  1. #1
    Join Date
    Sep 2007
    Posts
    2

    Reading value of elements opacity

    I couldn't find how to do this anywhere. Basically I want to toggle an elements opacity off and on through a link. The code I have is below but it doesn't read the value of the opacity to see if the div is currently 'on' or 'off'.

    I haven't found anywhere how to easily read the value of the opacity. Right now I am working in Firefox, but will want to make it IE friendly also.

    function show_hide(obj){
    var state = document.getElementById(obj).style.opacity;
    if (state == '90')
    opacity(obj, 0, 90, 500);
    else
    opacity(obj, 90, 0, 500);
    }

    function opacity(id, opacStart, opacEnd, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;
    if(opacStart > opacEnd) {
    for(i = opacStart; i >= opacEnd; i--) {
    setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
    timer++;
    }
    } else if(opacStart < opacEnd) {
    for(i = opacStart; i <= opacEnd; i++)
    {
    setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
    timer++;
    }
    }
    }

    function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.display = 'block';
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
    }

  2. #2
    Join Date
    Sep 2007
    Posts
    2
    Someone here must know

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles