SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast codlib's Avatar
    Join Date
    Jan 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question dynamically change opacity

    hi i want to change an images opacity dynamically in mozilla.
    im doing it when clicking a button. yhe code used is as follows.

    Code:
    document.getElementById('id').style.-moz-opacity =.5;
    but it is not working. i know the problem is with
    Code:
    style.-moz-opacity
    assignment. can anyone tell me a best solution.

    codlib

  2. #2
    Caveat surfer Buddy Bradley's Avatar
    Join Date
    May 2003
    Location
    Cambridge, UK
    Posts
    2,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Create a new CSS class with the reduced opacity, then just change the className of the element. You shouldn't be setting CSS properties in your JavaScript anyway.

  3. #3
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That should be
    Code:
    document.getElementById('id').style.MozOpacity = 0.5;
    Though you can use the property "opacity" instead. Its was implemented in gecko 1.7 (Firefox 1.0+)

    Buddy Bradley: Lets say that you want to fade away something. Surely you don't meat that you have 10 different CSS classes for that?

  4. #4
    Caveat surfer Buddy Bradley's Avatar
    Join Date
    May 2003
    Location
    Cambridge, UK
    Posts
    2,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, but you could write a function to transition between two classes, a 'visible' and a 'hidden' class.

  5. #5
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not sure I get you. What I meant was to change the opacity from 1.0 to 0.0. Meaning 1.0, 0.9, 0.8 etc

  6. #6
    SitePoint Enthusiast codlib's Avatar
    Join Date
    Jan 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    thank you Pepejeria....

    it is working
    Code:
    document.getElementById('id').style.MozOpacity = 0.5
    is working correctly..... thank you very much


Bookmarks

Posting Permissions

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