Framework7 comes with powerful and most modern touch slider ever - Swiper Slider with super flexible configuration and lot, lot of features.
Swiper Slider HTML Layout
Swiper HTML layout is pretty simple:
- <!-- Slider container -->
- <div class="swiper-container">
- <!-- Slides wrapper -->
- <div class="swiper-wrapper">
- <!-- Slides -->
- <div class="swiper-slide">Slide 1</div>
- <div class="swiper-slide">Slide 2</div>
- <div class="swiper-slide">Slide 3</div>
- ... other slides ...
- </div>
- <!-- Pagination, if required -->
- <div class="swiper-pagination"></div>
- </div>
Where:
-
swiper-container
- main slider container with slides and paginations. Required element-
swiper-wrapper
- additional wrapper for slides. Required element-
swiper-slide
- single slide element. Could contain any HTML inside
-
-
swiper-pagination
- container with pagination bullets. Note, that pagination bullets will be created automatically. Optional element
-
Initialize Swiper with JavaScript
Now, when we have Swiper' HTML, we need to initialize it. We need to use related App's method:
myApp.swiper(swiperContainer, parameters) - initialize slider with options
- swiperContainer - HTMLElement or string (with CSS Selector) of swiper container HTML element. Required.
- parameters - object - object with Swiper parameters. Optional.
- Method returns initialized Swiper instance
OR
new Swiper(swiperContainer, parameters) - initialize slider with options
- swiperContainer - HTMLElement or string (with CSS Selector) of swiper container HTML element. Required.
- parameters - object - object with Swiper parameters. Optional.
- Method returns initialized Swiper instance
For example:
- var mySwiper = app.swiper('.swiper-container', {
- speed: 400,
- spaceBetween: 100
- });
Swiper API (Parameters, Methods And Properties)
Сheck out Swiper API Website for the most relevant API parameters and methods.
Initialize Swiper with HTML
If you don't need Swiper callback you can initialize swiper using HTML without JavaScript. You can do that just by adding additional "swiper-init" class to swiper-container
- <!-- swiper-init to initialize swiper automatically -->
- <div class="swiper-container swiper-init">
- <div class="swiper-wrapper">
- <div class="swiper-slide">Slide 1</div>
- <div class="swiper-slide">Slide 2</div>
- <div class="swiper-slide">Slide 3</div>
- ... other slides ...
- </div>
- </div>
But what about Swiper parameters. In this case we need to pass them in data- attributes.
Parameters that used in camelCase, for example slidesPerView, in data- attributes should be used as hypens-case as data-slides-per-view
- <!-- swiper properties in data- attributes -->
- <div class="swiper-container swiper-init" data-speed="400" data-space-between="40" data-pagination=".swiper-pagination">
- <div class="swiper-wrapper">
- <div class="swiper-slide">Slide 1</div>
- <div class="swiper-slide">Slide 2</div>
- <div class="swiper-slide">Slide 3</div>
- ... other slides ...
- </div>
- <div class="swiper-pagination"></div>
- </div>
Or we can pass all Swiper parameters in valid JSON format in data-swiper attribute:
- <!-- swiper properties in JSON format in data-swiper attribute -->
- <div class="swiper-container swiper-init" data-swiper="{'speed':'400', 'spaceBetween':'40', 'pagination': '.swiper-pagination'}">
- <div class="swiper-wrapper">
- <div class="swiper-slide">Slide 1</div>
- <div class="swiper-slide">Slide 2</div>
- <div class="swiper-slide">Slide 3</div>
- ... other slides ...
- </div>
- <div class="swiper-pagination"></div>
- </div>
Access to Swiper's Instance
If you initialize Swiper using HTML it is still possible to access to Swiper's instance. It is "swiper" property of slider's container HTML element:
- var mySwiper = $$('.swiper-container')[0].swiper;
- // Now you can use all slider methods like
- mySwiper.slideNext();
Examples
Default Swiper with pagination
- /* A bit of demo styles */;
- .swiper-container {
- height: 100%;
- }
- .swiper-slide {
- background:#fff;
- }
- .swiper-slide span {
- text-align:center;
- display:block;
- margin:20px;
- font-size:21px;
- }
- ...
- <div class="page-content">
- <!-- Slider -->
- <div class="swiper-container">
- <div class="swiper-wrapper">
- <div class="swiper-slide"><span>Slide 1</span></div>
- <div class="swiper-slide"><span>Slide 2</span></div>
- <div class="swiper-slide"><span>Slide 3</span></div>
- <div class="swiper-slide"><span>Slide 4</span></div>
- </div>
- <div class="swiper-pagination"></div>
- </div>
- </div>
- ...
- var myApp = new Framework7();
- // Init slider and store its instance in mySwiper variable
- var mySwiper = myApp.swiper('.swiper-container', {
- pagination:'.swiper-pagination'
- });
Vertical Swiper
Styles and HTML layout are the same as in previous example
- var myApp = new Framework7();
- // Init slider and store its instance in mySwiper variable
- var mySwiper = myApp.swiper('.swiper-container', {
- pagination:'.swiper-pagination',
- direction: 'vertical'
- });
With space between slides
Styles and HTML layout are the same as in previous examples
- var myApp = new Framework7();
- // Init slider and store its instance in mySwiper variable
- var mySwiper = myApp.swiper('.swiper-container', {
- pagination:'.swiper-pagination',
- spaceBetween: 100 // 100px between slides
- });
Multiple Swipers
- .swiper-slide {
- background: #fff;
- box-sizing: border-box;
- border: 1px solid #ccc;
- }
- .swiper-slide span {
- text-align:center;
- display:block;
- margin: 20px;
- font-size:21px;
- }
- .swiper-container {
- height: 120px;
- margin: 35px 0;
- }
- <div class="page-content">
- <div class="content-block-title">1 Slide Per View, 50px Between</div>
- <div class="swiper-container swiper-1">
- <div class="swiper-pagination"></div>
- <div class="swiper-wrapper">
- <div class="swiper-slide"><span>Slide 1</span></div>
- <div class="swiper-slide"><span>Slide 2</span></div>
- ...
- <div class="swiper-slide"><span>Slide 10</span></div>
- </div>
- </div>
- <div class="content-block-title">2 Slides Per View, 20px Between</div>
- <div class="swiper-container swiper-2">
- <div class="swiper-pagination"></div>
- <div class="swiper-wrapper">
- <div class="swiper-slide"><span>Slide 1</span></div>
- <div class="swiper-slide"><span>Slide 2</span></div>
- ...
- <div class="swiper-slide"><span>Slide 10</span></div>
- </div>
- </div>
- <div class="content-block-title">3 Slides Per View, 10px Between</div>
- <div class="swiper-container swiper-3">
- <div class="swiper-pagination"></div>
- <div class="swiper-wrapper">
- <div class="swiper-slide"><span>Slide 1</span></div>
- <div class="swiper-slide"><span>Slide 2</span></div>
- ...
- <div class="swiper-slide"><span>Slide 10</span></div>
- </div>
- </div>
- <div class="content-block-title">Vertical, 0px Between</div>
- <div class="swiper-container swiper-vertical">
- <div class="swiper-pagination"></div>
- <div class="swiper-wrapper">
- <div class="swiper-slide"><span>Slide 1</span></div>
- <div class="swiper-slide"><span>Slide 2</span></div>
- ...
- <div class="swiper-slide"><span>Slide 5</span></div>
- </div>
- </div>
- <div class="content-block-title">Slow speed</div>
- <div class="swiper-container swiper-slow">
- <div class="swiper-pagination"></div>
- <div class="swiper-wrapper">
- <div class="swiper-slide"><span>Slide 1</span></div>
- <div class="swiper-slide"><span>Slide 2</span></div>
- ...
- <div class="swiper-slide"><span>Slide 10</span></div>
- </div>
- </div>
- </div>
- var myApp = new Framework7();
- // 1 Slide Per View, 50px Between
- var mySwiper1 = myApp.swiper('.swiper-1', {
- pagination:'.swiper-1 .swiper-pagination',
- spaceBetween: 50
- });
- // 2 Slides Per View, 20px Between
- var mySwiper2 = myApp.swiper('.swiper-2', {
- pagination:'.swiper-2 .swiper-pagination',
- spaceBetween: 20,
- slidesPerView: 2
- });
- // 3 Slides Per View, 10px Between
- var mySwiper3 = myApp.swiper('.swiper-3', {
- pagination:'.swiper-3 .swiper-pagination',
- spaceBetween: 10,
- slidesPerView: 3
- });
- // Vertical, 0px Between
- var mySwiperVertical = myApp.swiper('.swiper-vertical', {
- pagination:'.swiper-vertical .swiper-pagination',
- direction: 'vertical'
- });
- // Slow speed
- var mySwiperSlow = myApp.swiper('.swiper-slow', {
- pagination:'.swiper-slow .swiper-pagination',
- speed: 600
- });
Nested Swipers
Let's initialize slider in this example using just HTML:
- .swiper-slide {
- background:#fff;
- }
- .swiper-slide span {
- text-align:center;
- display:block;
- margin:20px;
- font-size:21px;
- }
- <div class="page-content">
- <!-- Horizontal parent slider -->
- <div data-pagination=".swiper-pagination-h"class="swiper-container swiper-init">
- <div class="swiper-pagination swiper-pagination-h"></div>
- <div class="swiper-wrapper">
- <div class="swiper-slide"><span>Horizontal Slide 1</span></div>
- <div class="swiper-slide">
- <!-- Vertical nested child slider -->
- <div class="swiper-container swiper-init" data-pagination=".swiper-pagination-v" data-direction="vertical">
- <div class="swiper-pagination swiper-pagination-v"></div>
- <div class="swiper-wrapper">
- <div class="swiper-slide"><span>Vertical Slide 1</span></div>
- <div class="swiper-slide"><span>Vertical Slide 2</span></div>
- <div class="swiper-slide"><span>Vertical Slide 3</span></div>
- </div>
- </div>
- </div>
- <div class="swiper-slide"><span>Horizontal Slide 3</span></div>
- <div class="swiper-slide"><span>Horizontal Slide 4</span></div>
- </div>
- </div>
- </div>
Custom Controls
- <div class="page-content">
- <div class="swiper-custom">
- <div class="swiper-container">
- <div class="swiper-pagination"></div>
- <div class="swiper-wrapper">
- <div class="swiper-slide"><span>Slide 1</span></div>
- <div class="swiper-slide"><span>Slide 2</span></div>
- <div class="swiper-slide"><span>Slide 3</span></div>
- <div class="swiper-slide"><span>Slide 4</span></div>
- <div class="swiper-slide"><span>Slide 5</span></div>
- <div class="swiper-slide"><span>Slide 6</span></div>
- <div class="swiper-slide"><span>Slide 7</span></div>
- </div>
- </div>
- <div class="swiper-button-prev"></div>
- <div class="swiper-button-next"></div>
- </div>
- </div>
- .swiper-custom {
- position:relative;
- height:100%;
- }
- .swiper-container {
- height:100%;
- }
- .swiper-slide {
- background: #fff;
- }
- .swiper-slide span {
- text-align:center;
- display:block;
- margin: 20px;
- font-size:21px;
- }
- .swiper-pagination-bullet {
- width: 10px;
- height: 10px;
- background: none;
- border:1px solid #aaa;
- border-radius: 0 0 0 0;
- opacity:1;
- cursor: pointer;
- }
- .swiper-pagination-bullet-active {
- background: #007aff;
- border-color: #007aff;
- }
- var myApp = new Framework7();
- var mySwiper = myApp.swiper('.swiper-container', {
- pagination: '.swiper-pagination',
- paginationHide: false,
- paginationClickable: true,
- nextButton: '.swiper-button-next',
- prevButton: '.swiper-button-prev',
- });
Lazy Loading
- <div class="swiper-container">
- <div class="swiper-wrapper">
- <div class="swiper-slide">
- <img data-src="http://lorempixel.com/1600/1200/nature/1" class="swiper-lazy">
- <div class="preloader"></div>
- </div>
- <div class="swiper-slide">
- <img data-src="http://lorempixel.com/1600/1200/nature/2" class="swiper-lazy">
- <div class="preloader"></div>
- </div>
- <div class="swiper-slide">
- <img data-src="http://lorempixel.com/1600/1200/nature/3" class="swiper-lazy">
- <div class="preloader"></div>
- </div>
- <div class="swiper-slide">
- <img data-src="http://lorempixel.com/1600/1200/nature/4" class="swiper-lazy">
- <div class="preloader"></div>
- </div>
- <div class="swiper-slide">
- <img data-src="http://lorempixel.com/1600/1200/nature/5" class="swiper-lazy">
- <div class="preloader"></div>
- </div>
- </div>
- <div class="swiper-pagination color-white"></div>
- </div>
- .swiper-container {
- height: 100%;
- }
- .swiper-slide {
- background: #000;
- position: relative;
- }
- .swiper-slide img {
- position: absolute;
- left:50%;
- top:50%;
- max-width: 100%;
- max-height: 100%;
- -webkit-transform: translate(-50%, -50%);
- transform: translate(-50%, -50%);
- }
- var mySwiper = new Swiper('.swiper-container', {
- preloadImages: false,
- lazyLoading: true,
- pagination: '.swiper-pagination'
- })
相关推荐
资源名称:iOS开发视频教程资源目录:【】iOS开发视频教程-第01讲-iOS历史介绍【】iOS开发视频教程-第02讲-XCode安装【】iOS开发视频教程-第03讲-UIView_PPT【】iOS开发视频教程-第04讲-UILabel【】iOS开发视频教程-...
Framework7 是免费开源的 HTML 移动端框架,用来开发混合移动端应用或者 iOS 7 的 Web 应用,并且带有 iOS 7 的原生外观和感觉。Framework7 也是独立的原型应用工具。Framework7 使用 Javascript,CSS 和 HTML 来...
资源名称:《iOS开发零基础入门教程》(40集)资源目录:【】传智播客《iOS开发零基础入门教程》1.1【】传智播客《iOS开发零基础入门教程》1.2【】传智播客《iOS开发零基础入门教程》1.3【】传智播客《iOS开发零基础...
framework7-icons, Framework7的免费iOS图标字体 Framework7图标Framework7的高级和免费ios图标字体。这种字体可以用在 Framework7插件中,但是你可以在任何地方看到它适合它,个人或者商业。 它是免费的使用和许可...
Framework7是一款免费、开源的移动应用框架,旨在为开发者提供构建iOS和Android应用的全套工具。它提供了丰富的组件库,包括导航、表单、视图、滑块等,使开发者能够轻松实现原生应用的界面和交互效果。 二、Vue.js...
之前遇到的需求,ios上没有类似的实现。搞了好久在网上搜了很多资料都不能解决最后找到了一个c/c++的底层源码,才实现了最后整理了下上传了。是个ios的demo很详细你定能看懂的。运行在xcode环境下,关键算法的文件是...
Objective-C是苹果公司开发的一种面向对象的编程语言,广泛应用于MacOS和iOS平台的软件开发。Cocoa是Apple为这两种操作系统提供的原生开发框架,包含了大量用于构建图形用户界面、处理事件、管理文件系统等任务的...
iPhone开发入门到精通视频教程资源目录:【】iOS开发源码系列---工具【】iOS开发源码系列---应用【】iOS开发源码系列---游戏【】iOS开发源码系列---类库与框架【】iOS开发真机测试与发布【】iOS开发视频教程01~05...
IOS开发框架、开发步骤、开发重点技术详细讲解.zip IOS开发框架、开发步骤、开发重点技术详细讲解.zip IOS开发框架、开发步骤、开发重点技术详细讲解.zip IOS开发框架、开发步骤、开发重点技术详细讲解.zip IOS开发...
提供的【应用】★★★★-iOS framework 制作教程【非静态包】源码示例,应该包含了完整的框架创建过程和相关代码,你可以通过阅读和运行这个项目来加深理解。在实践中,你可以尝试修改源代码,添加新的功能,或者...
### UI第一章:无限互联iOS开发教程课件 -- iPhone开发入门 #### iOS系统概述与架构 - **iOS系统**:作为苹果公司专为iPhone、iPod touch及iPad设计的操作系统,iOS自诞生以来就以其简洁易用的特点受到全球用户的...
移动端兼容安卓IOS的高仿支付密码输入功能。 类似支付宝,微信的支付密码功能。
Framework7 是免费开源的 HTML 移动端框架,用来开发混合移动端应用或者 iOS 7 的 Web 应用,并且带有 iOS 7 的原生外观和感觉。Framework7 也是独立的原型应用工具。
总之,手机移动端电商在iOS和Android平台上的实现涉及多方面的技术和策略。从H5页面的构建到原生功能的集成,再到用户体验的优化,每一个环节都需要精心设计和实施。随着技术的不断发展,未来的移动端电商将更加智能...
Framework7是一款强大的、免费的HTML5移动应用框架,专为构建具有原生iOS和Android界面风格的混合式移动应用而设计。它允许开发者使用Web技术(如HTML, CSS, JavaScript)来创建高度交互且功能丰富的应用程序,同时...
在iOS应用开发中,框架是至关重要的组成部分,它们提供了一系列预先编写好的类库和API,开发者可以基于这些框架快速构建功能丰富的应用程序。本资源“iOS开发框架”显然是一个专为学习和开发iOS应用而设计的集合,...
"ios开发-使用mpass移动开发框架在ios端抓包hook脚本.zip"是一个针对iOS开发者的重要资源,它包含了一套利用mpass移动开发框架在iOS设备上实现抓包功能的hook脚本。本文将详细介绍如何使用这个框架和脚本来实现iOS端...
iOS Debug环境 arm64与x86_64架构 WebRTC.framework Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit dynamically linked shared library x86_64] [arm64] Mach-O 64-bit dynamically linked ...
Appium 是一个流行的开源自动化测试框架,用于移动应用测试,支持iOS和Android平台。在iOS自动化测试领域,Appium 提供了对真实设备和模拟器的控制能力,使得开发者和测试工程师可以编写跨平台的自动化测试脚本。...