开源,免费,强大的PC/移动触摸滑动插件-Swiper

树叶云

开源,免费,强大的PC/移动触摸滑动插件-Swiper

 

Swiper是一个纯javascript创建的滑动特效插件,适用于手机、平板电脑等移动终端。Swiper可以实现常见的效果,如聚焦图像,标签切换,和多图像切换。Swiper开源、免费、稳定、使用简单、功能强大,是移动端网站建设的重要选择!

 

Swiper基础演示:http://www.swiper.com.cn/demo/index.html
开源,免费,强大的PC/移动触摸滑动插件-Swiper   Swiper在移动端的实际应用(演示):http://www.swiper.com.cn/demo/senior/index.html
开源,免费,强大的PC/移动触摸滑动插件-Swiper   Swiper在电脑端的实际应用(演示):http://www.swiper.com.cn/demo/web/index.html
开源,免费,强大的PC/移动触摸滑动插件-Swiper
开源,免费,强大的PC/移动触摸滑动插件-Swiper   Swiper中文API:http://www.swiper.com.cn/api/index.html
Swiper使用方法

1.首先加载插件,需要用到的文件有swiper.min.js和swiper.min.css文件。

<!DOCTYPE html>
<html>
<head>
    ...
    <link rel="stylesheet" href="path/to/swiper.min.css" rel="external nofollow"  rel="external nofollow" >
</head>
<body>
    ...
    <script src="path/to/swiper.min.js"></script>
</body>
</html>

如果你的页面加载了jQuery.js或者zepto.js,你可以选择使用更轻便的swiper.jquery.min.js。

<!DOCTYPE html>
<html>
<head>
    ...
    <link rel="stylesheet" href="path/to/swiper.min.css" rel="external nofollow"  rel="external nofollow" >
</head>
<body>
    ...
    <script src="path/to/jquery.js"></script>
    <script src="path/to/swiper.jquery.min.js"></script>
</body>
</html>

2.HTML内容。

<div class="swiper-container">
    <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>
    </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>
    
    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>
    
    <!-- 如果需要滚动条 -->
    <div class="swiper-scrollbar"></div>
</div>
导航等组件可以放在container之外

3.你可能想要给Swiper定义一个大小,当然不要也行。

.swiper-container { width: 600px; height: 300px; }  

4.初始化Swiper:是挨着</body>标签

<script> var mySwiper = new Swiper ('.swiper-container', { direction: 'vertical', loop: true, // 如果需要分页器 pagination: '.swiper-pagination', // 如果需要前进后退按钮 nextButton: '.swiper-button-next', prevButton: '.swiper-button-prev', // 如果需要滚动条 scrollbar: '.swiper-scrollbar', }) </script>
</body>

如果不能写在HTML内容的后面,则需要在页面加载完成后再初始化。

<script type="text/javascript">
window.onload = function() {
  ...
}
</script>

或者这样(Jquery和Zepto)

<script type="text/javascript">
$(document).ready(function () {
 ...
})
</script>

5.完成。恭喜你,现在你的Swiper应该已经能正常切换了,如果没有,你可以参考下这个测试包。现在开始添加各种选项和参数丰富你的Swiper,开启华丽移动前端创作之旅。

*建议不使用Source Map功能,请把js压缩文件最后一行
//# sourceMappingURL=maps/swiper.min.js.map 删掉。以免在某些浏览器出现以下提示:

开源,免费,强大的PC/移动触摸滑动插件-Swiper

如需要使用Source Map,演示包里面有该map文件,请放在相应的位置。

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/115107.html<

(0)
运维的头像运维
上一篇2025-02-18 00:22
下一篇 2025-02-18 00:23

相关推荐

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注