Results 1 to 2 of 2

Thread: Opacity Change on rollover

  1. #1
    Join Date
    Apr 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Opacity Change on rollover

    I know this is do-able with CSS, I just can't get it to work...

    I have an image with a link on it, I want that image to be at about 50% opacity on it's own, but I want it to go to 100% opacity when you hover over it, how do I do this?

  2. #2
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    Try this:
    Code:
    img.example {
    opacity: .5;
    }
    img.example:hover {
    opacity: 1;
    }
    Since this is CSS3, it's not supported by all browsers yet. A solution would be to use jQuery for this:
    HTML Code:
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript">
    $(function() {
    	$('img.example').css({
    		'opacity': .5
    	});
    	$('img.example').hover(function() {
    		$(this).animate({
    			'opacity': 1
    		});
    	},
    	function() {
    		$(this).animate({
    			'opacity': .5
    		});
    	});
    });
    </script>
    Good luck!

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
  •