Use JavaScript to implement the special effect of Flash glare and Fluctuation

Source: Internet
Author: User

Use JavaScript to implement the special effect of Flash glare and Fluctuation

The dazzling and fluctuating effects written in JavaScript show that some Flash effects are good, and JavaScript is used to simulate them. There are still many imperfections for your reference.

We can see that the implementation of flash animation is very convenient, so we try to figure it out. All are pixels simulated with dom, And the Sawtooth is inevitable ......

I'm afraid I have to add another filter to avoid the Sawtooth effect, or use an image.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<Html xmlns = "http://www.w3.org/1999/xhtml">

<Head>

<Title> dazzling fluctuations </title>

<Script>

Var lightWave = function (T, left, thick, sharp, speed, vibration, amplity, opacity ){

This. cont = T; // glare container

This. left = left; // The offset to the right of the glare

This. thick = thick; // width

This. sharp = sharp; // Sharpness

This. speed = speed; // fluctuation speed

This. vibration = vibration; // vibration frequency per unit time

This. amplitude = amplitude; // amplitude

This. opacity = opacity; // transparency

This. cont. style. position = 'relative ';

This. move ();

}

LightWave. prototype = {

Point: function (n, l, t, c, color ){

Var p = document. createElement ('P ');

P. innerHTML = '';

P. style. top = t + 'px ';

P. style. left = l + 'px ';

P. style. width = 1 + 'px ';

P. style. height = n + 'px ';

P. style. filter = 'Alpha (opacity = '+ this. opacity + ')';

P. style. lineHeight = 0;

P. style. position = 'absolute ';

P. style. background = color;

C. appendChild (p );

Return this;

},

Color: function (){

Var c = ['0', '3', '6', '9', 'C', 'F'];

Var t = [c [Math. floor (Math. random () * 100) % 6], '0', 'F'];

T. sort (function () {return Math. random ()> 0.5? -1:1 ;});

Return '#' + t. join ('');

},

Wave: function (){

Var l = this. left, t = this.wav elength, color = this. color ();

Var c = document. createElement ('div ');

C. style. top = this. amplitude + 20 + 'px ';

C. style. position = 'absolute ';

C. style. opacity = this. opacity/100;

For (var I = 1; I <this. thick; I ++ ){

For (var j = 0; j <this. thick * this. sharp-I * I; j ++, l ++ ){

This. point (I, l,-9999, c, color );

}

}

For (var I = this. thick; I> 0; I --){

For (var j = this. thick * this. sharp-I * I; j> 0; j --, l ++ ){

This. point (I, l,-9999, c, color );

}

}

This. cont. appendChild (c );

Return c;

},

Move: function (){

Var wl = this. amplwl;

Var vibration = this. vibration;

Var w = this.wav e (). getElementsByTagName ('P ');

For (var I = 0; I <w. length; I ++ ){

W [I]. I = I;

}

Var m = function (){

For (var I = 0, len = w. length; I <len; I ++ ){

If (w [I]. ori = true ){

W [I]. I-= vibration;

Var top = w [I]. I % 180 = 90? 0: wl * Math. cos (w [I]. I * Math. PI/180 );

W [I]. style. top = top + 'px ';

If (parseFloat (w [I]. style. top) <=-wl ){

W [I]. ori = false;

}

} Else {

W [I]. I + = vibration;

Var top = w [I]. I % 180 = 90? 0: wl * Math. cos (w [I]. I * Math. PI/180 );

W [I]. style. top = top + 'px ';

If (parseFloat (w [I]. style. top)> = wl ){

W [I]. ori = true;

}

}

}

}

SetInterval (m, this. speed );

}

}

Window. onload = function (){

Var targetDom = document. body;

New lightWave (targetDom, 36,120, 40 );

New lightWave (targetDom, 70,120, 30 );

}

</Script>

</Head>

<Body style = "background: #000; margin-top: 100px">

</Body>

</Html>

Parameters:

?

1

2

3

4

5

6

7

8

9

10

11

12

Var lightWave = function (T, left, thick, sharp, speed, vibration, amplity, opacity ){

This. cont = T; // Add a glare container

This. left = left; // The offset to the right when the glare occurs.

This. thick = thick; // width

This. sharp = sharp; // Sharpness

This. speed = speed; // fluctuation speed

This. vibration = vibration; // vibration frequency per unit time

This. amplitude = amplitude; // amplitude

This. opacity = opacity; // transparency

This. cont. style. position = 'relative ';

This. move ();

}

If you are interested, let's discuss it.

In addition, there is a problem that the transparency filter under ie in the code above does not work. It is learned that changing the location of the parent container will affect the inheritance of the transparent filter of the child node.

The above is all the content of this article. I hope you will like it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.