Detailed explanation of custom swiper component in JavaScript

Detailed explanation of custom swiper component in JavaScript

Effect display

insert image description here

Component Settings

Step 1

In the pages directory, create a new folder components

Step 2

Create a new folder swiper under components

In the swiper directory, create 4 new files, namely

  • swiper.
  • jsswiper.
  • jsonswiper.wxml
  • swiper.wxss

The location diagram of each file is as follows:

insert image description here

Note: At this time, the compilation will report an error. The error is displayed in json. Don't worry about it. Copy and paste the code later and compile it.

Step 3

Copy the following code into the four files in the swiper directory respectively

swiper.js

insert image description here

swiper.json

insert image description here

swiper.wxml

insert image description here

swiper.wxss

insert image description here

Using Components

Step 1

Introduce the component in the json file of the page where the swiper component is needed

{
  "usingComponents": {
    "custom-swiper": "../components/swiper/swiper"
  }
}

Note: …/components/swiper/swiper indicates the position of the component. You can replace it according to the position relationship you actually set.

Step 2

In the wxml page of the page, use the component code

<custom-swiper imgUrls="{{carouselImgUrls}}" />

carouselImgUrls

Type: Array Purpose: Used to store the address of the slideshow image (network address or local address)

Step 3

In the data of the js file of the page, add the carouselImgUrls variable

  data: {
    carouselImgUrls: [
    /*
    The number of pictures is customized. Picture source: Weibo Author: Girl Rabbit iiilass ​ ​​​​
 	Infringement and deletion */
      "https://wx1.sinaimg.cn/mw2000/7f97a73fly1gsgixv69f6j20j60j60ui.jpg",
      "https://wx1.sinaimg.cn/mw2000/7f97a73fly1gsgixvage4j20j60j6tah.jpg",
      "https://wx1.sinaimg.cn/mw2000/7f97a73fly1gsgixvadfnj20j60j60uk.jpg",
      "https://wx1.sinaimg.cn/mw2000/7f97a73fly1gsgixvdcswj20j60j6jt6.jpg",
      "https://wx1.sinaimg.cn/mw2000/7f97a73fly1gsgixv6kmbj20j60j6dhg.jpg"
    ],
  },

Finally, you only need to compile the code to get the effect diagram

insert image description here

Summarize

This article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of the difference between arrow functions and normal functions in JavaScript
  • Implementing carousel effects with JavaScript
  • javascript to switch pictures by clicking a button
  • Summary of various methods for JavaScript to determine whether it is an array
  • JavaScript to achieve fireworks effects (object-oriented)
  • JavaScript Canvas implements Tic-Tac-Toe game
  • Detailed discussion of the differences between loops in JavaScript
  • Summary of several common ways to abbreviate javascript code
  • 13 JavaScript one-liners that will make you look like an expert

<<:  Tutorial on how to connect and use MySQL 8.0 in IDEA's Maven project

>>:  Detailed explanation of the perfect solution to the VMware black screen problem after MacOS catalina upgrade

Recommend

After reading the introduction of CSS box model, you will not be confused

The property names often heard in web design: con...

Detailed explanation of Vue's seven value transfer methods

1. From father to son Define the props field in t...

How to build svn server in linux

1: Install SVN yum install -y subversion 2. Creat...

Three ways to align div horizontal layout on both sides

This article mainly introduces three methods of i...

Detailed analysis of the principles and usage of MySQL views

Preface: In MySQL, views are probably one of the ...

HTML optimization speeds up web pages

Obvious HTML, hidden "public script" Th...

Detailed explanation of MySQL sql99 syntax inner join and non-equivalent join

#Case: Query employee salary levels SELECT salary...

HTML discount price calculation implementation principle and script code

Copy code The code is as follows: <!DOCTYPE HT...

MySQL character set garbled characters and solutions

Preface A character set is a set of symbols and e...

How to set the page you are viewing to not allow Baidu to save its snapshot

Today, when I searched for a page on Baidu, becaus...

SQL Server database error 5123 solution

Because I have a database tutorial based on SQL S...

How to set static IP in centOS7 NET mode

Preface NAT forwarding: Simply put, NAT is the us...

Do you know the weird things in Javascript?

Our veteran predecessors have written countless c...

Tutorial on installing mysql5.7.18 on mac os10.12

I searched the entire web and found all kinds of ...

Example of how to import nginx logs into elasticsearch

The nginx logs are collected by filebeat and pass...