碧血红天的HomePage

微信小程序 — 实现轮播视图

一般在商城类型的APP上会有一个推荐维,展示几个主打的内容或商品,上面就循环轮播的展示几个图片。在微信小程序中,直接提供了一个swiper节点能够轻松愉快的实现这样的效果。

首先,我们需要几张图片。然后定义这个轮播视图的区域大小 ,首先我们通过wxss定义容器样式:

.ad_swiper_container {
  width: 100%;
  height: 150px;
  margin-top: 10px;
}

.ad_swiper_image {
  height:150px;
  width: 100%;
}

这里我我们定义了2个样式,一个是控制视图大小和偏移位置的。一个是里面图片的显示样式。接下来在wxml中书写效果。

<view class="ad_swiper_container">
  <swiper indicator-dots="true" autoplay="true" circular="true" indicator-color="#fff" indicator-active-color="#f77770">
    <block wx:for="{{array}}" wx:key="*this">
      <swiper-item style="background-color:#000;">
      <image src="{{item.url}}" class="ad_swiper_image" mode="widthFix"></image>
    </swiper-item>
    </block>
  </swiper>
</view>

swiper:是整个滑动视图的节点,它需要配合swiper-item节点使用。

swiper-item:代表里面具体的单个项,如果我们有2张图片,这里就有2个swiper-item节点。

这里我们通过js来控制图片的动态设置,我们在js文件中的data结构中定义一个代表图片地址的数组:

 data: {
    array:[{
      url:"/res/swiper_1.jpg"
    },{
      url:"/res/swiper_2.jpg"
    }]
  },

然后通过wx:for循环语法,在wxml中动态的创建swiper-item节点。上面的block节点相当于是个空节点,不会有任何视图效果,这里仅仅起到写wx:for这种动态代码的作用。在swiper-item中嵌入具体的内容即可,我们这里是图片,所以就单独嵌入一个image节点。

swiper上可以设置一些样式,比如是否显示当前展示的item的小圆点,圆点选中和非选中的颜色,是否循环显示,显示时长等等。

我这里不一一展示了,在微信小程序的官方文档上,对这些属性变量进行了说明,能够很方便的使用:

https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html

4747 评论

  1. I absolutely love your website.. Great colors & theme. Did you develop this site yourself? Please reply back as Iím planning to create my very own site and would love to learn where you got this from or just what the theme is named. Kudos!

  2. It’s hard to find knowledgeable people on this topic, but you sound like you know what you’re talking about! Thanks

  3. Pretty! This has been an extremely wonderful article. Thank you for supplying this info.

  4. hi opp ggeis 2022 ert go fi

  5. You are a very capable person!

  6. Iím amazed, I must say. Seldom do I encounter a blog thatís equally educative and entertaining, and without a doubt, you’ve hit the nail on the head. The issue is something too few men and women are speaking intelligently about. I am very happy that I stumbled across this in my hunt for something regarding this.

  7. You have made some really good points there. I looked on the web for more info about the issue and found most people will go along with your views on this website.

  8. Meta analysis serum vitamin D and breast cancer risk torsemide vs lasix

  9. An impressive share! I’ve just forwarded this onto a colleague who was doing a little research on this. And he actually ordered me dinner because I found it for him… lol. So allow me to reword this…. Thanks for the meal!! But yeah, thanks for spending the time to talk about this matter here on your website.

  10. The discrepancy may be due to the fact that in adult animals, tamoxifen acts by binding to estrogen receptor and inhibiting its activation propecia on sale

  11. Activated B cells should be plated in medium consisting of RPMI 1640 supplemented with 10 dialyzed fetal bovine serum, 250 Ојg ml xanthine, 15 Ојg ml hypoxanthine or 25 Ојg ml adenine, 10 Ојg ml thymidine, 2 Ојg ml aminopterin, 2 m M L glutamine, and 50 units ml of a penicillin streptomycin solution lasix purpose

  12. i had baseline ultrasound done, took clomid 100mg cd 3- 7, and then started testing with opk on cd12 rogaine vs propecia I am sincerely hoping praying to conceive soon

  13. Light greyish violet, round, curved with beveled edge, debossed with RIC on one side and NVR on the other side; available in least expensive azithromycin

  14. Perfectly written content material, thanks for information. “Necessity is the mother of taking chances.” by Mark Twain.

  15. Yeah bookmaking this wasn’t a speculative conclusion great post! .

  16. I?¦ll right away clutch your rss feed as I can not find your email subscription hyperlink or newsletter service. Do you have any? Please allow me understand so that I could subscribe. Thanks.

  17. You are a very bright person!

  18. The most effective point that you can utilize to remain ahead in life.

  19. Amazing is an all-in-one life management tool that will certainly help you remain on top of your to-dos, goals, and routine.

  20. Phenomenal is the perfect performance device for busy individuals that wish to get even more performed in much less time.

  21. No matter what your age, wish to do and be remarkable.

  22. Al-Ahliyya Amman University
    AAU Started providing academic services in 1990, Al-Ahliyya Amman University (AAU) was the first private university and pioneer of private education in Jordan. AAU has been accorded institutional and programmatic accreditation. It is a member of the International Association of Universities, Federation of the Universities of the Islamic World, Union of Arab Universities and Association of Arab Private Institutions of Higher Education. AAU always seeks distinction by upgrading learning outcomes through the adoption of methods and strategies that depend on a system of quality control and effective follow-up at all its faculties, departments, centers and administrative units. The overall aim is to become a flagship university not only at the Hashemite Kingdom of Jordan level but also at the Arab World level. In this vein, AAU has adopted Information Technology as an essential ingredient in its activities, especially e-learning, and it has incorporated it in its educational processes in all fields of specialization to become the first such university to do so.

    https://www.ammanu.edu.jo/

  23. Introducing Sensational, the productivity toolkit that can assist you function smarter and also live much better.

  24. Greetings! Very helpful advice on this article! It is the little changes that make the biggest changes. Thanks a lot for sharing!

  25. This is the solution you have actually been waiting on!

  26. hello there and thank you for your info – I’ve definitely picked up something new from right here. I did however expertise several technical points using this website, since I experienced to reload the web site many times previous to I could get it to load properly. I had been wondering if your web hosting is OK? Not that I’m complaining, but sluggish loading instances times will sometimes affect your placement in google and can damage your high quality score if advertising and marketing with Adwords. Well I’m adding this RSS to my e-mail and can look out for much more of your respective interesting content. Ensure that you update this again soon..

  27. Everyone loves what you guys are usually up too. Such clever work and exposure! Keep up the terrific works guys I’ve added you guys to my personal blogroll.

  28. Produced active individuals who want to be a lot more successful and productive .

  29. For those that are experienced in producing wonderful web content on their own!

  30. That’s right, it’s a software that permits you to be much more effective.

  31. Most of what you claim happens to be supprisingly appropriate and it makes me wonder the reason why I had not looked at this in this light before. This particular article really did turn the light on for me personally as far as this specific topic goes. However there is just one factor I am not really too comfortable with so whilst I make an effort to reconcile that with the actual main theme of the point, allow me observe exactly what the rest of the readers have to point out.Very well done.

  32. This simply could be the life-changing item you’ve been waiting for.

  33. I will make your life a lot easier, you will not understand exactly how to thank me.

  34. Hi there, You’ve done an excellent job. I will certainly digg it and individually suggest to my friends. I am confident they will be benefited from this website.

  35. From time management to setting goal, we will certainly help you accomplish extra in less time.

  36. The Amazingness allows you get more performed in much less time, without all the anxiety.

  37. Amazingness is a lifestyle that shoots one’s capacity to do marvels.

  38. You deserve this life time chance to have whatever you’ve ever before desired.

  39. Come to be a master in everything with this!

  40. Remarkable capacity to obtain points done.

  41. You deserve the very best life needs to provide. Amazingness is here to help you get it!

  42. Incredible is a life transforming tool that will assist you be a lot more efficient and get better results.

  43. Efficiency, health and wellness and also well being, rest better!

  44. best online poker nj online poker pennsylvania poker online school

  45. legalize online gambling online gambling ohio online gambling free bonus no deposit

  46. Howdy! This is my first visit to your blog! 카지노사이트We are a collection of volunteers and starting a new project in a community in the
    same niche.Your blog provided us useful information to work on. You have done a extraordinary job!

  47. web site this is very good, I like, material that is too awesome and, unique, continue to work if you sure eat certainly can, me comet with hope can help you ask for permission okay totosoju

  48. When you want to prosper in something, it is essential that you have a look whatsoever the options readily available.