Home WeChat Applet Mini Program Development Detailed explanation of WeChat applet implementation of following menu effects and loop nested loading of data examples

Detailed explanation of WeChat applet implementation of following menu effects and loop nested loading of data examples

Jan 16, 2018 am 09:50 AM
Applets Effect menu

本文主要为大家详细介绍了微信小程序实现跟随菜单效果和循环嵌套加载数据,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能帮助到大家。

效果如图:

代码如下:

wxml


//使用循环嵌套data数据格式写对即可
<scroll-view class="left" scroll-y>  
  <view wx:for="{{left}}" class="leftlist {{index==_click?&#39;yes&#39;:&#39;&#39;}}" data-i="{{index}}" bindtap="tap">
   {{item.txt}}
  </view>
 </scroll-view>

<scroll-view class="right" scroll-y bindscroll="scroll" scroll-into-view="{{toView}}">
  <view id="{{item.id}}" wx:for="{{right}}">

   <view class="title">
    <text class="line"></text>
    {{item.txt}}
    <text class="line"></text>
   </view> 

   <view class="li" wx:for="{{item.li}}">
    <image src="{{item.src}}"></image>
    <text class="name">{{item.name}}</text>
   </view>

  </view>
 </scroll-view>
Copy after login

js


Page({
 data: {
  toView: &#39;red1&#39;,
  _click:0,
  left: [{ txt: &#39;新品&#39;, id: &#39;new&#39; }, { txt: &#39;手机&#39;, id: &#39;phone&#39; }, { txt: &#39;电视&#39;, id: &#39;mv&#39; }, { txt: &#39;电脑&#39;, id: &#39;computer&#39; }],
  right: [
   { txt: &#39;新品&#39;, id: &#39;new&#39;,li: [{ src: &#39;../../assets/images/max1.jpg&#39;, name: &#39;小米noto&#39; }, { src: &#39;../../assets/images/max1.jpg&#39;, name: &#39;小米mix&#39; }, { src: &#39;../../assets/images/max3.jpg&#39;, name: &#39;小米5c&#39; }, { src: &#39;../../assets/images/max2.jpg&#39;, name: &#39;小米notp&#39; }, { src: &#39;../../assets/images/max2.jpg&#39;, name: &#39;小米note5&#39; }, { src: &#39;../../assets/images/max2.jpg&#39;, name: &#39;小米6&#39; }]}, 
   { txt: &#39;手机&#39;, id: &#39;phone&#39;,li: [{ src: &#39;../../assets/images/max2.jpg&#39;, name: &#39;小米6s&#39; }, { src: &#39;../../assets/images/max3.jpg&#39;, name: &#39;小米max&#39; }, { src: &#39;../../assets/images/max2.jpg&#39;, name: &#39;小米5s&#39; }, { src: &#39;../../assets/images/max1.jpg&#39;, name: &#39;小米li&#39; }, { src: &#39;../../assets/images/max3.jpg&#39;, name: &#39;小米4&#39; }, { src: &#39;../../assets/images/max1.jpg&#39;, name: &#39;小米max&#39; }]}, 
   { txt: &#39;电视&#39;, id: &#39;mv&#39;, li: [{ src: &#39;../../assets/images/max3.jpg&#39;, name: &#39;小米6&#39; }, { src: &#39;../../assets/images/max2.jpg&#39;, name: &#39;小米mix&#39; }, { src: &#39;../../assets/images/max1.jpg&#39;, name: &#39;小米7s&#39; }, { src: &#39;../../assets/images/max3.jpg&#39;, name: &#39;小米2&#39; }, { src: &#39;../../assets/images/max1.jpg&#39;, name: &#39;小米note7&#39; }, { src: &#39;../../assets/images/max3.jpg&#39;, name: &#39;小米8&#39; }] }, 
   { txt: &#39;电脑&#39;, id: &#39;computer&#39;, li: [{ src: &#39;../../assets/images/max1.jpg&#39;, name: &#39;小米2&#39; }, { src: &#39;../../assets/images/max1.jpg&#39;, name: &#39;小米mix&#39; }, { src: &#39;../../assets/images/max2.jpg&#39;, name: &#39;小米max&#39; }, { src: &#39;../../assets/images/max1.jpg&#39;, name: &#39;小米6&#39; }, { src: &#39;../../assets/images/max3.jpg&#39;, name: &#39;小米note&#39; }, { src: &#39;../../assets/images/max1.jpg&#39;, name: &#39;小米max&#39; }] }]
 },

 scroll: function (e) {
  console.log(e)//右侧列表滑动-左侧列表名称样式跟着改变,然而我不会写,搁置中,谁会告诉我,谢谢!
 },
 tap: function (e) { 
  var j = parseInt(e.currentTarget.dataset.i);
  this.setData({
   toView: this.data.left[j].id,//控制视图滚动到为此id的<view>
   _click:j           //控制左侧点击后样式
    })
 },
})
Copy after login

wxss


page{border-top:1px solid #f6f6f6;}

.left{
 height:100%;
 width: 19%;
 display: inline-block;
 background:#fff;
 text-align:center;
 border-right:1px solid #eee;
 }
.leftlist{
 font-size:12px;
 padding:10px;
 }

.right{
 height:100%;
 width: 80%;
 display: inline-block;
 background:#fff;
 text-align:center;
 }

.line{
 width:15px;
 height:1px;
 background:#ddd;
 display:inline-block;
 vertical-align:super;
 margin:0 15px;
}

.li{ 
 height:10%;
 width:30%;
 display:inline-block;
 text-align:center;
}

.li image{width:60px;height:60px;}

.li .name{
 font-size:12px;
 display:block;
 color:#888;
 overflow:hidden;
 white-space:nowrap;
 text-overflow:ellipsis;
}

.title{padding:20px 0;}
.yes{color: #f99;font-size: 14px;}
Copy after login

友情提示:

1、左侧点击样式改变:

利用自身index与点击的元素的index比较。
data-i=“{{获取当前index传给_click保存}}”,
class=”leftlist {{index==_click?'yes':”}}”,
此处index是自身的,如果自身和点击的一致就添加,yes类名,否侧滞空清除yes样式。

2、点击左侧,右侧跟随:

利用scroll-into-view=”{{id}}”, 视图会滚动到id为此id的view标签。我是直接从data数据里取得id,也可以直接获取点击元素id。

3、循环嵌套:data数据格式写对,按照官方文档就行。

相关推荐:

JS简单实现滑动加载数据实例分享

实例详解ajax实现加载数据功能

微信小程序页面滑动屏幕加载数据的实例详解

The above is the detailed content of Detailed explanation of WeChat applet implementation of following menu effects and loop nested loading of data examples. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Users encounter rare glitches: Samsung Watch smartwatches suddenly experience white screen issues Users encounter rare glitches: Samsung Watch smartwatches suddenly experience white screen issues Apr 03, 2024 am 08:13 AM

You may have encountered the problem of green lines appearing on the screen of your smartphone. Even if you have never seen it, you must have seen related pictures on the Internet. So, have you ever encountered a situation where the smart watch screen turns white? On April 2, CNMO learned from foreign media that a Reddit user shared a picture on the social platform, showing the screen of the Samsung Watch series smart watches turning white. The user wrote: "I was charging when I left, and when I came back, it was like this. I tried to restart, but the screen was still like this during the restart process." Samsung Watch smart watch screen turned white. The Reddit user did not specify the smart watch. Specific model. However, judging from the picture, it should be Samsung Watch5. Previously, another Reddit user also reported

Windows 11: The easy way to import and export start layouts Windows 11: The easy way to import and export start layouts Aug 22, 2023 am 10:13 AM

In Windows 11, the Start menu has been redesigned and features a simplified set of apps arranged in a grid of pages, unlike its predecessor, which had folders, apps, and apps on the Start menu. Group. You can customize the Start menu layout and import and export it to other Windows devices to personalize it to your liking. In this guide, we’ll discuss step-by-step instructions for importing Start Layout to customize the default layout on Windows 11. What is Import-StartLayout in Windows 11? Import Start Layout is a cmdlet used in Windows 10 and earlier versions to import customizations for the Start menu into

Kyushu Fengshen Assassin 4S Radiator Review Air-cooled 'Assassin Master' Style Kyushu Fengshen Assassin 4S Radiator Review Air-cooled 'Assassin Master' Style Mar 28, 2024 am 11:11 AM

Speaking of ASSASSIN, I believe players will definitely think of the master assassins in "Assassin's Creed". They are not only skilled, but also have the creed of "devoting themselves to the darkness and serving the light". The ASSASSIN series of flagship air-cooled radiators from the appliance brand DeepCool coincide with each other. Recently, the latest product of this series, ASSASSIN4S, has been launched. "Assassin in Suit, Advanced" brings a new air-cooling experience to advanced players. The appearance is full of details. The Assassin 4S radiator adopts a double tower structure + a single fan built-in design. The outside is covered with a cube-shaped fairing, which has a strong overall sense. It is available in white and black colors to meet different colors. Tie

Exquisite light and shadow art in spring, Haqu H2 is the cost-effective choice Exquisite light and shadow art in spring, Haqu H2 is the cost-effective choice Apr 17, 2024 pm 05:07 PM

With the arrival of spring, everything revives and everything is full of vitality and vitality. In this beautiful season, how to add a touch of color to your home life? Haqu H2 projector, with its exquisite design and super cost-effectiveness, has become an indispensable beauty in this spring. This H2 projector is compact yet stylish. Whether placed on the TV cabinet in the living room or next to the bedside table in the bedroom, it can become a beautiful landscape. Its body is made of milky white matte texture. This design not only makes the projector look more advanced, but also increases the comfort of the touch. The beige leather-like material adds a touch of warmth and elegance to the overall appearance. This combination of colors and materials not only conforms to the aesthetic trend of modern homes, but also can be integrated into

Huntkey MX750P full module power supply review: 750W of concentrated platinum strength Huntkey MX750P full module power supply review: 750W of concentrated platinum strength Mar 28, 2024 pm 03:20 PM

With its compact size, the ITX platform has attracted many players who pursue the ultimate and unique beauty. With the improvement of manufacturing processes and technological advancements, both Intel's 14th generation Core and RTX40 series graphics cards can exert their strength on the ITX platform, and gamers also There are higher requirements for SFX power supply. Game enthusiast Huntkey has launched a new MX series power supply. In the ITX platform that meets high-performance requirements, the MX750P full-module power supply has a rated power of up to 750W and has passed 80PLUS platinum level certification. Below we bring the evaluation of this power supply. Huntkey MX750P full-module power supply adopts a simple and fashionable design concept. There are two black and white models for players to choose from. Both use matte surface treatment and have a good texture with silver gray and red fonts.

Easily understand 4K HD images! This large multi-modal model automatically analyzes the content of web posters, making it very convenient for workers. Easily understand 4K HD images! This large multi-modal model automatically analyzes the content of web posters, making it very convenient for workers. Apr 23, 2024 am 08:04 AM

A large model that can automatically analyze the content of PDFs, web pages, posters, and Excel charts is not too convenient for workers. The InternLM-XComposer2-4KHD (abbreviated as IXC2-4KHD) model proposed by Shanghai AILab, the Chinese University of Hong Kong and other research institutions makes this a reality. Compared with other multi-modal large models that have a resolution limit of no more than 1500x1500, this work increases the maximum input image of multi-modal large models to more than 4K (3840x1600) resolution, and supports any aspect ratio and 336 pixels to 4K Dynamic resolution changes. Three days after its release, the model topped the HuggingFace visual question answering model popularity list. Easy to handle

Implement card flipping effects in WeChat mini programs Implement card flipping effects in WeChat mini programs Nov 21, 2023 am 10:55 AM

Implementing card flipping effects in WeChat mini programs In WeChat mini programs, implementing card flipping effects is a common animation effect that can improve user experience and the attractiveness of interface interactions. The following will introduce in detail how to implement the special effect of card flipping in the WeChat applet and provide relevant code examples. First, you need to define two card elements in the page layout file of the mini program, one for displaying the front content and one for displaying the back content. The specific sample code is as follows: &lt;!--index.wxml--&gt;&l

Colorful Hidden Star P15 24 Review: A hard-core all-round gaming laptop with both good looks and performance Colorful Hidden Star P15 24 Review: A hard-core all-round gaming laptop with both good looks and performance Mar 06, 2024 pm 04:40 PM

In the current era of rapid technological development, laptops have become an indispensable and important tool in people's daily life and work. For those players who have high performance requirements, a laptop with powerful configuration and excellent performance can meet their hard-core needs. With its excellent performance and stunning design, the Colorful Hidden Star P15 notebook computer has become the leader of the future and can be called a model of hard-core notebooks. Colorful Hidden Star P1524 is equipped with a 13th generation Intel Core i7 processor and RTX4060Laptop GPU. It adopts a more fashionable spaceship design style and has excellent performance in details. Let us first take a look at the features of this notebook. Supreme equipped with Intel Core i7-13620H processing

See all articles