Results 1 to 10 of 10

Thread: image opacity question

  1. #1
    Join Date
    Jul 2005
    Location
    UK
    Posts
    159
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Question image opacity question

    i have seen several tutorials on how to apply slick image rollovers with different states of opacity. but this only seems to make images LIGHTER.

    i would like to make all my linked images 50% DARKER on hover. is this possible? perhaps by overlaying a black png file with 50% transparency? i'm afraid i don't know how. any help?

    i swear i've seen it but am having trouble remembering where.

    thank you in advance.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The easiest way to do it is to wrap your images in an element with a black background, then vary their opacity.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2005
    Location
    UK
    Posts
    159
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    sorry, im still learning. can you explain what you mean by 'wrap' and 'element' and also exactly how to vary the opacity? i've noticed many techniques fail on certain browsers.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Put image on a black "thing", then turn down opacity with CSS.
    http://www.mandarindesign.com/opacity.html
    (First thing on a google search for "css opacity".)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Another fairly easy approach would be simply to start out with a dark image, one that is as dark as you want it to become. Set its initial opacity to 50%. Then when you want it to get "50% darker", set its opacity to 100%.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Jul 2005
    Location
    UK
    Posts
    159
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    thanks guys, it worked fine, i just figured there had to be another way short of putting it on top a "black thing", cause now i've put black things behind 50 images in an already code-heavy thumbnail gallery.

    too bad its not possible to overlay one image with another transparent image through css. maybe in the future?

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Another fairly easy approach would be simply to start out with a dark image, one that is as dark as you want it to become. Set its initial opacity to 50%. Then when you want it to get "50% darker", set its opacity to 100%.
    Hm. Less flexible, and would lose image quality.
    i just figured there had to be another way short of putting it on top a "black thing", cause now i've put black things behind 50 images in an already code-heavy thumbnail gallery.
    Use JS to generate the wrapper elements, if your effect requires JS anyway.
    too bad its not possible to overlay one image with another transparent image through css. maybe in the future?
    You can now. However, it still requires a separate element.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by moscarda View Post
    too bad its not possible to overlay one image with another transparent image through css. maybe in the future?
    This can currently be done:

    HTML Code:
    <div style="position:relative;">
    <img src="under.jpg">
    <img src="over.jpg" 
    style="position:absolute;top:0;left:0;opacity:0;filter:alpha(opacity=0);">
    </div>
    CSS style used is the most basic that will work in current release modern browsers that support opacity, and is shown inline for simplicity's sake.
    Last edited by jscheuer1; 02-16-2008 at 08:47 PM. Reason: grammar
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Jul 2005
    Location
    UK
    Posts
    159
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey View Post
    Use JS to generate the wrapper elements, if your effect requires JS anyway
    can you point me to a js that does this sort of thing, or would i have to write it from scratch? i don't know js, i've only gotten this far by learning how to customize preexisting scripts to my needs.

    Quote Originally Posted by Twey View Post
    You can now. However, it still requires a separate element.
    can you explain? please and thanks

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    for (var e = document.images, s, i = e.length - 1; i >= 0; --i)
      if (e[i].className.indexOf("darken") > -1)
        (s = document.createElement("span")).appendChild(e[i].parentNode.replaceChild(s, e[i])).parentNode.style.backgroundColor = "black";
    can you explain?
    Same principle, but using an image rather than a flat background colour.
    Last edited by Twey; 02-16-2008 at 11:20 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •