Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 10 of 10
  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    4
    Member #
    28893
    Hi, I've got a script the should change the opacity of an image on click, but it fails to change them, despite changing the class.

    HTML Code:
    <div id="container">
        <a href="#"><img src="images\thumb1.png" class="thumbs" /></a>
        <a href="#"><img src="images\thumb1.png" class="thumbs" /></a>
        <a href="#"><img src="images\thumb1.png" class="thumbs" /></a>
    </div
    the CSS

    .visited {opacity:0.4;}
    .thumbs {opacity:0.8;}

    and the script

    Code:
    $(document).ready(function(){
    
    $("#photo").css("top", ($(window).height()-($("#photo").outerHeight()))/2);
    $("#photo").css("left", ($(window).width()-($("#photo").outerWidth()))/2);
    
        $("#container img").hover(function(){
            $(this).stop().fadeTo("fast", 1.0)},function(){
            $(this).stop().fadeTo("fast", 0.8)});
    
        $("#container img").click(function(){
            $(this).addClass("visited").removeClass("thumbs");
            $("#modalWindow").fadeTo(1500,0.6,function(){
                $("#photo").fadeTo(2000,1);
                });
            });
    
        $("#modalWindow").click(function(){
            $("#photo").fadeOut(1000,function(){
            $("#modalWindow").fadeOut(500);
            });
    
        });
    });
    Can anyone help?

    Thanks

  2.  

  3. #2
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Lose the JS and just do it with CSS:

    .thumbs{opacity:0.8;}
    .thumbs:active{opacity:0.4;}

    From there, make sure you also add the MS filter version of opacity so it will work there too.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  4. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    4
    Member #
    28893
    I wanted to add the class so that the image would remain at the lower opacity when the user returns to the thumbnail page. I tried to add the :active pseudo class to the anchor, but it keeps returning to opacity:0.8.

    When I check Firebug, the console says that the class has been changed, but the browser doesn't respond in the way I expected.

    I guess my real question is 'Why doesn't Firefox respond to the change in class of an element'.

  5. #4
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    Then you probably wanted the :visited pseudo-class. When it's visited, that's what shows up.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  6. #5
    WDF Staff George Dolidze's Avatar
    Join Date
    Apr 2011
    Location
    Irvine, CA
    Posts
    2,487
    Member #
    27540
    Liked
    416 times
    Quote Originally Posted by TheGAME1264, post: 216324
    Then you probably wanted the :visited pseudo-class. When it's visited, that's what shows up.
    I always wondered: How long does the :visited class last? Is it until you exit the site, or is it until you delete your cookies or something..?
    My freelancer website: DolidzeDesign



    You only need a parachute if you plan on skydiving twice.

  7. #6
    Junior Member
    Join Date
    Aug 2011
    Posts
    4
    Member #
    28893
    The :visited pseudo-class doesn't change the opacity of the anchors, and the links are all to the same place. I was trying to change a class, but FF doesn't notice the change of class>

  8. #7
    WDF Staff George Dolidze's Avatar
    Join Date
    Apr 2011
    Location
    Irvine, CA
    Posts
    2,487
    Member #
    27540
    Liked
    416 times
    did you do:
    a:visited{
    opacity: .6
    }
    ?
    My freelancer website: DolidzeDesign



    You only need a parachute if you plan on skydiving twice.

  9. #8
    Junior Member
    Join Date
    Aug 2011
    Posts
    4
    Member #
    28893
    Quote Originally Posted by George Dolidze, post: 216514
    did you do:
    a:visited{
    opacity: .6
    }
    ?

    Yeah, I tried that, but it renders all of the links opacity 0.6 instead of just the one that is clicked.

  10. #9
    WDF Staff George Dolidze's Avatar
    Join Date
    Apr 2011
    Location
    Irvine, CA
    Posts
    2,487
    Member #
    27540
    Liked
    416 times
    That is because you've clicked on them before. If you want it to change opacity while it is being clicked, then instead of :visited do :active.
    My freelancer website: DolidzeDesign



    You only need a parachute if you plan on skydiving twice.

  11. #10
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    Wait a minute...this is getting really confusing. I just want to get this straight.

    You've got a thumbnail gallery.
    Someone clicks on an image link.
    The opacity of the image changes on click (this is the part that sounds like it's working).
    Someone then visits another page, comes back to the original page somehow, and the image "opacities" don't reset.

    Am I getting this? Because when I first read this, I thought it was some sort of odd nav bar thing.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Remove Ads

Posting Permissions

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

Search tags for this page

change opacity of active picture link css
,

change opacity on click

,
change opacity on click css
,
css visited opacity
,
image opacity active
,
img click opacity
,

on click change opacity

,

onclick change image opacity

,
onclick change opacity of image
,
opacity image active
Click on a term to search for related topics.
All times are GMT -6. The time now is 04:40 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com