Some details can make your web page attracting. We have learn that how to make the colorful frame in one article. Now we will learn how to make the scroll bar change colors when the mouse is on it. In fact, it is common that many scroll bars of web sites can change their color when the mouse is on it. You can find this phenomenon in almost every website. So it is necessary for us to master how to achieve this special effect whether you want to use it or not at the moment. Now follow me step by step.
First, open the web page you have made in the past. The original web page is like the following picture. The color of the scroll bar is definite by the Internet Explorer automatically.
|
Second, click the code button and open the code view. Then put the following blue text into the section between <head> and </head>.
- <script language="JavaScript1.2">
- <!--
- function scrollBar(line,face,theme)
- {
- if (!line||!face)
- {
- line=null;
- face=null;
- switch(theme) // Predefined themes
- {
- case "blue":
- var line="#78AAFF";
- var face="#EBF5FF";
- break;
- case "orange":
- var line="#FBBB37";
- var face="#FFF9DF";
- break;
- case "red":
- var line="#FF7979";
- var face="#FFE3DD";
- break;
- case "green":
- var line="#00C600";
- var face="#D1EED0";
- break;
- case "neo":
- var line="#BC7E41";
- var face="#EFE0D1";
- break;
- }
- }
- with(document.body.style)
- {
- scrollbarDarkShadowColor=line;
- scrollbar3dLightColor=line;
- scrollbarArrowColor="black";
- scrollbarBaseColor=face;
- scrollbarFaceColor=face;
- scrollbarHighlightColor=face;
- scrollbarShadowColor=face;
- scrollbarTrackColor="#F3F3F3";
- }
- }
- /*------------------[Pointer coordinates catcher]---------------*/
- function colorBar(){
- var w = document.body.clientWidth;
- var h = document.body.clientHeight;
- var x = event.clientX;
- var y = event.clientY;
- if(x>w) scrollBar('#000080','#BFDFFF'); // Your colors
- else scrollBar(null,null,"neo"); // A predefined theme
- }
- if (document.all){
- scrollBar(null,null,"neo");
- document.onmousemove=colorBar;
- }
- //-->
- </script>
Third, go back to the design view and save the document. Then press F12 key to preview the effect in the Internet Explorer. The scroll bar’s colors are like the following picture. You can see the scroll bar of the first picture, whose color is pink. And the color of the second picture’s scroll bar is light blue when the mouse is on it.
|
|
OK, now we have already finished the special effect that the scroll bar can change color when the mouse is on it. Of course you can change it into other colors. It is very easy. We just need to use the “function scrollBar” and “function colorBar” function codes. This special effect is very common, so we should master it adroitly. Practice again until you master these ways.

