The following editor will bring you a JavaScript+CSS photo album special effects example code. The editor thinks it's pretty good, so now I'll share the source code of JavaScript+css with you, and give it a reference. If you are interested in making photo albums with JavaScript and css, please follow the editor to take a look.
Well, this is such an example. A special effect learned in the video is not very useful in practice. But it can help understand the JS language and become familiar with CSS3 styles.
Design:
Observe the changes in a picture and find:
1. Picture scaling (random , and not at the same time)
1. From large to small
2. From small to large, transparency from 1 to 0 (start immediately after the first step of exercise is completed)
2. Picture rotation (random, and not moving at the same time. It needs to start after all movements are completed)
3. Because each picture starts to transform randomly, the starting time is different. Here you can set a delayer setTimeout, and the time can be randomly generated using random.
4. A self-executing function needs to be used in the middle. Because setTimeout ignores i in the for loop, i may be wrong every time the delayer runs. Use a self-executing function to save i value every time.
5. The p of the button cannot be clicked during the conversion and needs to be marked and judged.
6. There are two types of motion, scaling and rotation. Note that the rotation can only start after the scaling is completed. This must also be handled well.
Notes:
scale is the scaling
transition transition, delay
sub-function Modifying the value of the father is a closure
The self-executing function is mainly used to save each value of i
If you add a timer directly, it will not matter The outer loop will be executed after 1s. At this time, i doesn’t know where it is, and it may be out of bounds
The value generated by Math.random() is a parameter of setTimeout. Delay time
setTimeout delay time is also affected by the computer card
transitionend will be executed as long as the transition is made, it is calculated based on the style
Zooming and transparency will trigger transitionend
call() changes the object pointed to by this
Then it is implemented directly, and this special effect is run when the page is loaded.
Fill in some information found in the middle:
1.CSS3 opacity attribute:
Value | Description |
---|---|
value | Specify opacity. From 0.0 (fully transparent) to 1.0 (fully opaque) |
inherit | The value of the Opacity attribute should be inherited from the parent element |
2.HTML DOM scale() method:
Parameters
Parameters | Description |
---|---|
sx, sy | Horizontal and vertical scaling factors. |
Description
The scale() method adds a scaling transformation to the current transformation matrix of the canvas. Scaling is done with independent horizontal and vertical scaling factors. For example, passing a value of 2.0 and 0.5 will cause the drawing path to be twice as wide and 1/2 as tall. Specifying a negative sx value causes the X coordinate to be folded along the Y axis, and specifying a negative sy causes the Y coordinate to be folded along the X axis.
My direct parameter here is to reduce the height and width at the same time
3.
p is a block label. In this case, the label of p will be adjusted by the height of the picture inside. Hold it up, img tags float to the left by default, exactly 10 per line, each 80px
margin: 0 auto is the abbreviation of margin: 0 auto 0 auto, that is, the left and right are automatically centered. As for why they are not next to each other The upper p, this should be the upper margin: 80px auto, and the outer margin of the lower p has been set to 80px distance
The height of btn has not been set, it is supported by font
The rest is The code is detailed, the comments are very detailed, and there are many callback functions. . :
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
The above is all the content of this article, I hope it can help everyone learn! !
Related recommendations:
Javascript array flattening method is explained in detail
JavaScript implements the select drop-down box Sharing examples of adding and deleting elements in
Javascript algorithm binary search tree sample code
The above is the detailed content of JavaScript+CSS photo album special effects example code. For more information, please follow other related articles on the PHP Chinese website!