View, ScrollView, and Swiper of WeChat applet

Source: Internet
Author: User
The view controls of applets are explained and demonstrated by the system today. I believe they will be easy to use after reading them. First, let's take a look at the running effect of this sample program. The view controls of applets are explained and demonstrated by the system today. I believe they will be easy to use after reading them.

First, let's take a look at the running effect of this sample program.

The WXML code of the index page is as follows:

 
 
  
   
{Motto }}
  
  
 
  
   
    
View component demonstration
   
  
 
 
  
   
    
Scroll-View component demonstration
   
  
 
 
  
   
    
Swiper component demonstration
   
  
 

The JS code of the index page is as follows:

Var app = getApp () Page ({data: {motto: 'Basic View, Slide View, slider Swiper ', userInfo :{}}, onLoad: function () {console. log ('onload') var that = this // call the method of the application instance to obtain the global data app. getUserInfo (function (userInfo) {// update the data that. setData ({userInfo: userInfo })})}})

The WXSS style code on the index page is as follows:

/** Index. wxss **/. usermotto {margin-top: 30px; font-size: 20px ;}. viewName {margin-top: 30px; margin-left: 40px; margin-right: 40px; height: 50px; font-size: 25px; background-color: # AED2EE; /** the following shows how to set up the text content of the three view views to center up and down **/justify-content: center; display: flex; align-items: center ;}

In addition, we need to remind you that each page uses some identical styles. in this case, you can extract these styles and place them in the app. wxss file as public styles.
The public style in this Demo is as follows, which is written in app. wxss.

/** App. wxss **/page {background-color: # fbf9fe; height: 100%;}/** you can put the public styles used on all pages of the entire Applet here, to facilitate direct calls to each page **/. viewTitle {margin-top: 20px; height: 40px; text-align: center ;}. bc_green {background-color: #09BB07 ;}. bc_red {background-color: # F76260 ;}. bc_blue {background-color: #10 AEFF ;}. bc_yellow {background-color: # FFBE00 ;}. bc_gray {background-color: # C9C9C9 ;}

1. Basic View component page:

The WXML code of the View page is as follows:

 
 
     
  
   
Style 1: horizontal arrangement
      
          
   
    
111
           
   
    
222
           
   
    
333
       
  
 
 
     
  
   
Style 2: vertical arrangement
      
  
           
   
    
111
           
   
    
222
           
   
    
333
       
  
 

The WXSS code of the View page is as follows:

/** View. wxss **/. flex-wrp {height: 100px; display: flex; background-color: # ffffff;}/** a style is defined here. In addition, the app is a small program. wxss can also define general styles and apply them to each page. **/. Flex-item {width: 100px; height: 100px; color: # ffffff; display: flex; justify-content: center; align-items: center ;}

Because the View component is demonstrated here, there is no JS code. You can view the animation at the top of the page.

Second, the sliding view component page is as follows:

The WXML code of the ScrollView page is as follows:

 
     
  
   
ScrollView display
    
   
 
     
  
   
Style 1, Vertical sliding Vertical
      
      
         
         
            
            
            
            
          
       
  
 
 
     
  
   
Style 2, Horizontal sliding Horizontal
      
      
           
            
            
            
          
       
  
 

The JS code of the ScrollView page is as follows:

//ScrollView.jsvar order = ['green', 'red', 'yellow', 'blue', 'green']Page({})

The WXSS code of the ScrollView page is as follows:

/** ScrollView. wxss ** // ** for more source code, download from the 51 applet source code section: [url] http://bbs.html51.com/f-36-1/#/url?#/.scroll-view_h {white-space: nowrap ;}. scroll-view-item {height: 200px ;}. scroll-view-item_H {display: inline-block; width: 100%; height: 200px ;}. flex-wrp {height: 200px; display: flex; background-color: # ffffff ;}

You can view the animation at the top of the page.

Third, the Swiper view component page is as follows:

The WXML code of the Swiper page is as follows:

   
     
  
   
Swiper view display
    
   
     
        
           
              
                 
                
             
          
       
      
        
   Show/cancel indicator      
   {Vertical? 'Horizontal display': 'Vertical Display '}}      
   Start/Stop carousel    
      
      
  
   
Duration of one Carousel
      
      
  
   
How long does the interval take to display the next graph interval?
    
 

The JS code on the Swiper page is as follows:

// Swiper. jsPage ({data: {background: ['green', 'red', 'yellow'], indicatorDots: true, // boolean value variable, controls vertical: false, // controls the slider view based on the true or false boolean value, and controls autoplay: false in horizontal or vertical mode, whether to start or stop carousel interval: 3000, // Set the interval to display the next figure duration: 1200 // Set the time of one carousel}, changeIndicatorDots: function (e) {this. setData ({indicatorDots :! This. data. indicatorDots})}, changeVertical: function (e) {this. setData ({vertical :! This. data. vertical})}, changeAutoplay: function (e) {this. setData ({autoplay :! This. data. autoplay})}, intervalChange: function (e) {this. setData ({interval: e. detail. value})}, durationChange: function (e) {this. setData ({duration: e. detail. value })}})

The WXSS code on the Swiper page is as follows:

/**Swiper.wxss**/.swiper-item{  display: block;  height: 150px;}

For more information about views, scrollviews, and Swiper of the three widgets, see PHP!

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.