Reputation: 5779
I am making a user interface where I need to highlight a cell in a table. I have already used coloring for something else, so I need to use the borders. I have created the css to change the borders to dashed, but that doesn't highlight much. I would like to know if there is any way to animate the borders so that they would flash, or circle (typical dashed border animation). I tried with @keyframes and animation, but failed miserably.
I am happy to do it with javascript do it, but I can't use jQuery or any other framework.
If anyone has any other suggestion for highlighting a cell, that could help too.
A test code I use is this:
<table class="t">
<tr>
<td class="t">1</td>
<td class="t top">2</td>
<td class="t">3</td>
</tr>
<tr>
<td class="t left">4</td>
<td class="t middle">5</td>
<td class="t right">6</td>
</tr>
<tr>
<td class="t">7</td>
<td class="t bottom">8</td>
<td class="t">9</td>
</tr>
</table>
CSS:
table.t {
border-collapse: collapse;
border:1px;
table-layout:fixed;
}
td.t {
border: 1px solid black;
width: 50px;
}
td.top {
border-bottom: 1px dashed black;
}
td.left {
border-right: 1px dashed black;
}
td.right {
border-left: 1px dashed black;
}
td.bottom {
border-top: 1px dashed black;
}
td.middle {
border: 1px dashed black;
}
Jsfiddle available HERE
Upvotes: 2
Views: 5660
Reputation: 5923
Simple JavaScript answer:
var blinkStatus = 'off',
currentBlinkElement = null,
blinkTimer,
blinkSpeed = 500,
stopBlinkButton = document.getElementById( 'stopBlinkButton' );
function blink( element )
{
currentBlinkElement = element;
if( blinkStatus == 'off' ) {
currentBlinkElement.className = currentBlinkElement.className + ' blink-on';
blinkStatus = 'on';
} else {
currentBlinkElement.className = currentBlinkElement.className.replace( ' blink-on', '' );
blinkStatus = 'off';
}
blinkTimer = setTimeout( function(){ blink( element ); }, blinkSpeed );
}
function stopBlink()
{
clearTimeout( blinkTimer );
if( currentBlinkElement != null ) {
currentBlinkElement.className = currentBlinkElement.className.replace( ' blink-on', '' );
currentBlinkElement = null;
}
}
document.onclick = function( e ) {
var clickedElement;
if(e == null) {
clickedElement = event.srcElement;
} else {
clickedElement = e.target;
}
if( clickedElement.tagName == 'TD' ) {
stopBlink();
blink( clickedElement );
}
};
stopBlinkButton.onclick = function(){
stopBlink();
};
JSFiddle working example: http://jsfiddle.net/2Vfu5/. Click a table cell to start.
Upvotes: 1
Reputation: 105883
you can use border image, gradients, en even mutiple box-shadow to draw borders.
animation or transition on hover can animate them too.
examples with gradient : http://codepen.io/gc-nomade/pen/jdwgG and for the fun too , the animated version http://codepen.io/anon/pen/rHxCg
or with box shadow (sorry for the flashy) : http://codepen.io/gcyrillus/pen/bGFLA
you also have outline and outline-offset http://jsfiddle.net/2822m/4/
table.t {
border-collapse: collapse;
border:1px;
table-layout:fixed;
}
td.t {
border:1px solid;
width: 50px;
}
td.top {
border-bottom: none;
}
td.left {
border-right:none;
}
td.right {
border-left: none;
}
td.bottom {
border-top: none;
}
td.middle {
border: 1px solid red;
outline:1px dashed black;
outline-offset:-1px;
}
animation is then easy http://jsfiddle.net/2822m/5/
td.middle {
border: 1px solid red;
outline:1px dashed black;
outline-offset:-1px;
animation:blink 1s infinite;
}
@keyframes blink {
50% {
outline:1px dashed yellow;
}
}
Upvotes: 1
Reputation: 13586
Not sure exactly what you're looking for, but here's a simple keyframe that applies a box shadow and one that changes transparency... You'll have to add the appropriate vendor prefixing, of course.
CSS
td.selected {
-webkit-animation: pulse-border 1s infinite;
}
// pulsing border
@-webkit-keyframes pulse-border {
from, to { box-shadow: 0 0 0 0 black;}
50% { box-shadow: 0 0 0 4px black; }
}
// flash the cell contents if applied to cell
@-webkit-keyframes flash {
from, to { opacity: 1 }
50% { opacity: 0 }
}
edit
Also made this one for fun... A rotating type border. DEMO... Just kind of sucks because of all the extra elements.
Upvotes: 6