Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a glowing border on a textarea like Twitter?

in twitter this is the normal alt text

and this is hover glow alt text

is there a jquery plugin or code or css effect can do that

like image 945
Mostafa Elkady Avatar asked Dec 08 '10 12:12

Mostafa Elkady


People also ask

How do you add a glow border?

In this tutorial, you'll find some methods of creating a glowing border around an input field with CSS properties. In the example below, we add the :focus pseudo-class to the <input> element and then, specify the border-color and box-shadow properties. Also, we set the outline property to “none”.


2 Answers

It's just CSS:

textarea:focus {
 border-radius: 0 0 8px rgba(82, 168, 236, 0.5);
 rgba(82, 168, 236, 0.75);
}

Doesn't work in IE yet though, and for FireFox you have to use the vendor prefix: -moz-border-radius

like image 117
Stephan Muller Avatar answered Oct 28 '22 12:10

Stephan Muller


Have you tried the .focus event? http://api.jquery.com/focus/ You can do something like:

$(document).ready(function()
{
    $('twiter_textareas_selector').focus(function()
    {
         $(this).css('border':'blue 3px solid');
    }).blur(function()
    {
         $(this).css('border':'gray 1px solid');
    });
});

Usually, it's better to use classes to do this (methods .addClass() and .removeClass() ), but the example is only to show the idea. :)

I don't know if there is an way doing it by css, but by jquery is difficult to appear different behaviours from one navigator to another.

I have done some tests on twitter site, so I'he found those properties used in chrome and firefox. If you don't want the glow set them like this:

-moz-box-shadow: 0 0 0 none;
-webkit-transition: border 0 linear;
-webkit-box-shadow: 0 linear;

In other navigators there will be more properties to set, because the first is only for firefox and the next are for webkit based browsers like chrome. And .unbind('focus blur') because twitter use them to make sure all the navigators see the pages correctly.

A code like this:

$(document).ready(function()
{
    $('twiter_textareas_selector').unbind('blur focus'); //try to stop the twitter scripts
    $('twiter_textareas_selector').focus(function()
    {
         $(this).css('moz-box-shadow': '0 0 0 none', '-webkit-transition': 'border 0 linear', '-webkit-box-shadow': '0 linear');
    });
});

I hope it helps you! ^^

like image 28
Jayme Tosi Neto Avatar answered Oct 28 '22 10:10

Jayme Tosi Neto