Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize the function of picture rotation with html5+div+css+js

Shulou Source: shulou.com Published: 2022-06-02 05:13:57 09月30日 Update

This article mainly explains "how to use html5+div+css+js to realize the image carousel function", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to use html5+div+css+js to realize the picture carousel function"!

1. image tag

label

Labels used to display pictures. Its Src attribute is used to set the image source. In fact, you can also set width directly to set the width of the image, and set height to refer to the height of the image. It is worth noting that once the width of the image is set, the height of the image will automatically scale according to the image scale.

2. script tag

marker

Here we begin to write js code, which is used to control the logic of html tags on web pages, commonly known as DOM control. Mark of comment//single line comment/*... */multiline comment

2.1 logic

There's a logic control for picture switching, which is the change in n variables.

n++ means n=n+1 to switch picture names

2.2 dom control

document.getElementById("value corresponding to ID of tag in html") Returns a corresponding tag object.

innerHTML represents all html code inside a container.

3. Symbol-html correspondence

Symbol correspondence.

Spaces correspond to 20% of urls

4. summary

1. Learn to download pictures and make pictures

2, write js, it is best to learn zero-based VB tutorial, if there is no experience, then write according to

3. Write more and practice

4. setInterval to do timer, parameter 1 is a function, parameter 2 is time (milliseconds)

5. function(){ } This is an anonymous function that can be called directly

Material:

Source Code:

index.html file

Home-Liu Jinyu Programming Liu Jinyu Programming

main.css file

body{ margin:0;}.logo{ color:white; font-weight: bolder; padding:10px; font-size: 20px; background-color:#9ACD32;}#pics img{ width: 100%;} At this point, I believe that everyone has a deeper understanding of "how to use html5+div+css+js to realize the image carousel function." You may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Tags: Picture label control function code comment logic learning content function parameter width file mark symbol height Liu Jin switching programming practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information OPPO Reno Xiaomi Microsoft macOS