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. . :
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> /*图片容器整体样式,左右居中 视角景深800px */ #imgWrap{ width: 800px; height: 400px; margin: 80px auto; perspective: 800px; } /*左对齐,高宽*数量=整体p*/ #imgWrap img{ float: left; width: 80px; height: 80px; } #btn{ width: 100px; /*height: 40px 这里不定义就是跟font大小一样*/ background: rgb(0,100,0); padding: 0 20px; /*font-size 和 line-height 中可能的值。*/ font: 16px/40px "微软雅黑"; color: #fff; margin: 0 auto; border-radius: 5px; box-shadow: 2px 2px 5px #000; cursor: pointer; } </style> <script> /* * 1、图片缩放(随机,并且不是同时运动) * 1、从大到小 * 2、从小到大,透明度从1到0(在第一步运动完成后立马开始) * * 2、图片旋转(随机,并且不是同时运动的。需要在全部运动走完以后开始) */ window.onload=function(){ var btn=document.getElementById("btn"); // 选择所有元素 var imgs=document.querySelectorAll("img"); var endNum=0; //它代表图片运动完成的数量 var canClick=true; //它代表用户能否再次点击 btn.onclick=function(){ if(!canClick){ return; //以下的代码不要走了 } canClick=false; for(var i=0;i<img src="/static/imghwm/default1.png" data-src="images/1.jpg" class="lazy" s.length;i++){ (function(i){ setTimeout(function(){ /*imgs[i].style.transition='100ms'; imgs[i].style.transform='scale(0)'; imgs[i].style.opacity='0'; imgs[i].addEventListener('transitionend',function(){ console.log(1); });*/ motion(imgs[i],'50ms',function(){ this.style.transform='scale(0)'; },function(){ motion(this,'1s',function(){ this.style.transform='scale(1)'; this.style.opacity='0'; },function(){ //在这里表示图片缩放的运动已经全部完成了,接着走第二个运动 endNum++; if(endNum==imgs.length){ //所有的运动都完成了 //console.log('所有的运动都完成了') rotate(); //endNum=0; } }); }); },Math.random()*1000); })(i); } }; //旋转功能 function rotate(){ for(var i=0;i<img src="/static/imghwm/default1.png" data-src="images/1.jpg" class="lazy" s.length;i++){ //给运动来一下初始化 imgs[i].style.transition=''; /*imgs[i].style.opacity=1;*/ imgs[i].style.transform='rotateY(0deg) translateZ(-'+Math.random()*500+'px)'; //运动来了,自执行函数 (function(i){ setTimeout(function(){ motion(imgs[i],'2s',function(){ this.style.opacity=1; this.style.transform='rotateY(-360deg) translateZ(0)'; },function(){ endNum--; //因为在上次运动结束的时候,endNum的值已经加到了50了 //console.log(endNum); if(endNum==0){ //所有的运动都完成了 canClick=true; //endNum=0 } }); },Math.random()*1000); })(i); } } //运动函数 function motion(obj,timer,doFn,callBack){ //motion(运动对象,运动时间(字符串+单位),运动属性(函数),运动结束后的回调函数) obj.style.transition=timer; doFn.call(obj);//改变对象 var end=true; //用来知道过渡有没有完成一次 //结束事件处理函数 function endFn(){ if(end){ //callBack&&callBack.call(obj); if(callBack){ callBack.call(obj); } end=false; //改成false,下次就不会走这个if了 } obj.removeEventListener('transitionend',endFn); //结束后就把这个事件取消掉,要不它会一直带在身上 } obj.addEventListener('transitionend',endFn); } }; </script> </head> <body> <p id="imgWrap"> <img src="/static/imghwm/default1.png" data-src="images/1.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/2.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/3.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/4.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/5.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/6.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/7.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/8.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/9.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/10.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/11.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/12.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/13.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/14.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/15.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/16.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/17.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/18.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/19.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/20.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/21.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/22.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/23.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/24.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/25.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/26.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/27.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/28.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/29.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/30.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/31.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/32.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/33.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/34.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/35.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/36.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/37.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/38.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/39.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/40.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/41.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/42.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/43.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/44.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/45.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/46.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/47.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/48.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/49.jpg" class="lazy" alt="" /> <img src="/static/imghwm/default1.png" data-src="images/50.jpg" class="lazy" alt="" /> </p> <p id="btn">点击查看效果</p> </body> </html>
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!

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor