• RSS
  • Facebook
  • Twitter
Comments


Created by Martin Angelov on Jun 1st, 2010
Gradients
Tutorialzine is the home to some of the best web development tutorials on the net. Our focus has mainly been on the coding side of web development, but often creating a good design is equally important.
This is why today we are going to do the first tutorial on the site, which is both design and code oriented, to bring you the full web development experience. Share your thoughts on what you think about this new format in the comment section below.

Step 1 – Design

Today we are creating a neon glow text effect with CSS and jQuery. The first step to achieving this effect, is to create a background image, which contains two slightly different versions of the text. jQuery fades between those two versions creating a smooth transition effect.
To create the colorful background image, you first need to open a new Photoshop document 650px wide and 300px high, with a background color of #141414. Use your favorite typeface to write your heading. I used Century Gothic with a size of 60px.
After this Ctrl-click the text layer’s icon in the layers panel to select it.
Ctrl+Click on the Text Layer
Ctrl+Click on the Text Layer
Use the Rectangular Marquee Tool while holding Shift+Alt to limit the selection to a single word of the text.
Shift + Alt to Limit the Selection
Shift + Alt to Limit the Selection
While everything is selected, create a new layer, name it gradients and make it active by clicking it.
Create a new Layer
Create a new Layer
Choose the Gradient tool from the toolbox, and color the words one by one using the technique discussed above to switch the selection between the individual words. These selections limit the effect of the gradient tool and with the “gradients” layer being the currently active one, all changes made by the tool are saved there.
Gradients
Gradients
After you finish the heading, duplicate it below the original and apply a different set of gradients. Align the two versions of the colorful heading one above the other, so that it is easy to switch between them by simply providing a different value for the position of the background image in the CSS part.
The Finished Background Image
The Finished Background Image
You can find the PSD file that I created for this tutorial in the download archive.

Step 2 – XHTML

The XHTML markup is really simple, you just need a container (the #neonText H1) which holds the two versions of the background.

demo.html

1<h1 id="neonText">
2    Neon Text Effect With jQuery & CSS.
3    <span class="textVersion" id="layer1">span>
4    <span class="textVersion" id="layer2">span>
5h1>
Layer1 is shown above layer2, and lowering its opacity will create a smooth neon glow effect as the background image of the span below it fades into view.
For SEO reasons, we are also providing the content of the image in plain text. It is neatly hidden from view with a negative text-indent.

Step 3 – CSS

The styles, used by the effect are also pretty straightforward. The two spans share the same background image we did in step one, but by specifying a different background position, we show only the top or the bottom part of the image.

styles.css

01/* The two text layers */
02#neonText span{
03    width:700px;
04    height:150px;
05    position:absolute;
06    left:0;
07    top:0;
08 
09    background:url('img/text.jpg') no-repeat left top;
10}
11 
12span#layer1{
13    z-index:100;
14}
15 
16span#layer2{
17    background-position:left bottom;
18    z-index:99;
19}
20 
21/* The h1 tag that holds the layers */
22#neonText{
23    height:150px;
24    margin:180px auto 0;
25    position:relative;
26    width:650px;
27    text-indent:-9999px;
28}
The #neonText container is positioned relatively, so that the absolutely positioned spans inside it are shown exactly one on top of the other. Also notice the negative text-indent, which we are using to hide the contents of the container.

Step 4 – jQuery

The last step involves setting up the transitioning animation. As we are using the jQuery library (which we include in the page with a script tag), a couple of useful methods are made available – fadeIn and fadeOut, which we are using the code below.

script.js

01$(document).ready(function(){
02 
03    setInterval(function(){
04 
05        // Selecting only the visible layers:
06        var versions = $('.textVersion:visible');
07 
08        if(versions.length<2){
09            // If only one layer is visible, show the other
10            $('.textVersion').fadeIn(800);
11        }
12        else{
13            // Hide the upper layer
14            versions.eq(0).fadeOut(800);
15        }
16    },1000);
17 
18});
The function inside of the setInterval statement is executed once every second and shows or hides the first span layer.
With this our slick neon glow effect is complete!

Conclusion

You can use this effect to freshen up your designs while still keeping the SEO value of your pages. I am sure that you can think of many interesting uses and modifications of this code. Be sure to share what you do with the community in the comment section below.


Postado por Fernando Schimit - Fox Creative

Categories: ,

Leave a Reply