Skip to main content

Is there a better way of achieving this effect?



I have an image thumbnail with a light colored border which, on mouseover, I want to crossfade to a dark colored border. I'm thinking that the easiest way to achieve this would be to fade in a second div with a darker border over the existing one.





Is there a better or different way to fade in a border color change?





Thanks.


Comments

  1. Load the jQuery UI into your page. Included with the core package (if I'm not mistaken; you may need to customize your download package) is the ability to use jQuery's .animate() on color values (and/or transitions between two CSS classes). This is something absent from the core jQuery library out-of-the-box.

    With that, you can just do something as menial as the following:

    // e.g. assuming #foo has default border-color #999999
    $('#foo').on('mouseover', function () {
    $(this).animate({
    borderColor : "#333333"
    });
    });


    Modify according to your interests.

    ReplyDelete
  2. There are many ways.

    One is through CSS3 transitions. Although not working in IE, you can have it progressively enhanced to modern browsers.

    assuming your div has a class of imageBorder:

    div.imageborder {border-color: #FFFFFF;}
    div.imageBorder:hover {
    border-color: #FF0000;
    -webkit-transition: all 1s ease-in-out;
    -moz-transition: all 1s ease-in-out;
    -o-transition: all 1s ease-in-out;
    -ms-transition: all 1s ease-in-out;
    transition: all 1s ease-in-out;
    }


    The other way is to use javascript, Here is a jQuery sample:

    $('div.imageBorder').hover(
    function(){
    $(this).animate({
    border-color: '#FF0000',
    },200,function(){});
    },
    function(){
    $(this).animate({
    border-color: '#FFFFFF',
    },200,function(){});
    }
    );


    This will work in IE as well, but at the cost of loading an extra library.

    ReplyDelete
  3. Put your thumbnail inside a DIV with light colored border (default), later on mouseover find the div and change the style (border-width and border-color), although it is not a fadding style but as user quickly mouseover and mouseout on the image looks like minor fadding effect that is enough i guess. Write your own javascript code to make it faster (jQuery surely gets more time javascript code) .

    ReplyDelete
  4. Can you apply a CSS3 transition on the border color?

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.