What's a good way to insert a flashing cursor (e.g. a flashing thick underscore in DOS or vertical bar in Linux) in HTML?
This character/image would be trailing the H1 header and should look good at different sizes.
To animate the cursor, first, we need to define a keyframe called cursor-blink that will reduce the opacity of the cursor to 0 when the keyframe is “0%”. Once done, we can now use this keyframe on the cursor using the animation shorthand like so.
You can do this with just CSS, here is vertical bar Fiddle
h1 {
font-size: 20px;
padding-right: 20px;
display: inline-block;
}
h1:after {
content: '';
width: 20px;
height: 2px;
background: black;
opacity: 0;
display: inline-block;
animation: blink 1s linear infinite alternate;
}
@keyframes blink {
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<h1>Lorem ipsum dolor sit amet</h1>
Or you can use JQuery and setInterval
setInterval(function() {
$('span').animate({
opacity: 1
}, 600).animate({
opacity: 0
}, 600)
}, 1200);
h1 {
font-size: 20px;
padding-right: 20px;
display: inline-block;
}
h1 span {
width: 20px;
margin-bottom: -1px;
height: 2px;
background: black;
opacity: 0;
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Lorem ipsum dolor sit amet <span></span></h1>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With