• We just launched and are currently in beta. Join us as we build and grow the community.

Cursor Sparkle Effect using Javascript

Alfie

Cyber Risk Analyst
A Rep
0
0
0
Rep
0
A Vouches
0
0
0
Vouches
0
Posts
102
Likes
91
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
In this chapter we are about to learn how to make a sparkle effect in your mouse cursor. You can download and use this in your projects or systems. Just follow the instructions below.

Instructions

Writing our css code

  1. <style type=

    "text/css"

    >


  2. BODY{
  3. overflow-x

    :

    hidden

    ;
  4. }

  5. .s1
  6. {
  7. position

    :

    absolute

    ;
  8. font-size

    :

    10pt

    ;
  9. color

    :

    blue

    ;
  10. visibility

    :

    hidden

    ;
  11. }

  12. .s2
  13. {
  14. position

    :

    absolute

    ;
  15. font-size

    :

    18pt

    ;
  16. color

    :

    red

    ;
  17. visibility

    :

    hidden

    ;
  18. }

  19. .s3
  20. {
  21. position

    :

    absolute

    ;
  22. font-size

    :

    14pt

    ;
  23. color

    :

    gold

    ;
  24. visibility

    :

    hidden

    ;
  25. }

  26. .s4
  27. {
  28. position

    :

    absolute

    ;
  29. font-size

    :

    12pt

    ;
  30. color

    :

    lime

    ;
  31. visibility

    :

    hidden

    ;
  32. }


  33. </style>

Writing our javacript code

  1. <

    SCRIPT LANGUAGE=

    "javascript"

    TYPE=

    "text/javascript"

    >

  2. var

    standardbody=

    (

    document.compatMode

    ==

    "CSS1Compat"

    )

    ?

    document.documentElement

    :

    document.body

  3. var

    nav =

    (

    !

    document.all

    ||

    window.opera

    )

    ;
  4. var

    tmr =

    null

    ;
  5. var

    spd =

    50

    ;
  6. var

    x =

    0

    ;
  7. var

    x_offset =

    5

    ;
  8. var

    y =

    0

    ;
  9. var

    y_offset =

    15

    ;

  10. document.onmousemove

    =

    get_mouse;

  11. function

    get_mouse(

    e)
  12. {
  13. x =

    (

    nav)

    ?

    e.pageX

    :

    event.clientX

    +

    standardbody.scrollLeft

    ;
  14. y =

    (

    nav)

    ?

    e.pageY

    :

    event.clientY

    +

    standardbody.scrollTop

    ;
  15. x +=

    x_offset;
  16. y +=

    y_offset;
  17. beam(

    1

    )

    ;
  18. }

  19. function

    beam(

    n)
  20. {
  21. if

    (

    n<

    5

    )
  22. {
  23. document.getElementById

    (

    'div'

    +

    n)

    .style

    .top

    =

    y+

    'px'
  24. document.getElementById

    (

    'div'

    +

    n)

    .style

    .left

    =

    x+

    'px'
  25. document.getElementById

    (

    'div'

    +

    n)

    .style

    .visibility

    =

    'visible'
  26. n++;
  27. tmr=

    setTimeout(

    "beam("

    +

    n+

    ")"

    ,

    spd)

    ;
  28. }
  29. else
  30. {
  31. clearTimeout(

    tmr)

    ;
  32. fade(

    4

    )

    ;
  33. }
  34. }

  35. function

    fade(

    n)
  36. {
  37. if

    (

    n>

    0

    )
  38. {
  39. document.getElementById

    (

    'div'

    +

    n)

    .style

    .visibility

    =

    'hidden'
  40. n--;
  41. tmr=

    setTimeout(

    "fade("

    +

    n+

    ")"

    ,

    spd)

    ;
  42. }
  43. else

    clearTimeout(

    tmr)

    ;
  44. }

  45. </

    SCRIPT>

Lastly, our html code

  1. <DIV

    ID

    =

    "div1"

    CLASS

    =

    "s1"

    >

    *</

    DIV

    >
  2. <DIV

    ID

    =

    "div2"

    CLASS

    =

    "s2"

    >

    *</

    DIV

    >
  3. <DIV

    ID

    =

    "div3"

    CLASS

    =

    "s3"

    >

    *</

    DIV

    >
  4. <DIV

    ID

    =

    "div4"

    CLASS

    =

    "s4"

    >

    *</

    DIV

    >

  5. <p

    align

    =

    "center"

    ><font

    face

    =

    "arial"

    size

    =

    "3"

    >

    Do you have source code, articles, tutorials, web links, <br

    /

    >

    and books to share? You can write your own content here. <br

    /

    >

    You can even have your own blog.</

    font

    ><br

    >
  6. <font

    face

    =

    "arial, helvetica"

    size

    =

    "5"

    ><a

    href

    =

    "http://sourcecodester.com"

    >

    Sourcecodester</

    a

    ></

    font

    >
  7. </

    p

    >
  8. <p

    align

    =

    "center"

    ><font

    face

    =

    "arial"

    size

    =

    "3"

    >

    Move yourr cursor around to get the effect.</

    font

    ><br

    ></

    p

    >

Finally, you have successfully created a sparkling cursor effect. For more questions, suggestions and queries, feel free to comment below or email me at [email protected]

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

 

442,401

317,942

317,951

Top