欢迎您光临自学哈网,只为分享网络知识教程,供大家学习参考!

「自学哈网」开源,免费,强大的PC/移动触摸滑动插件-Swiper

作者 : 自学哈 本文共2098个字,预计阅读时间需要6分钟 2023-06-7 共95人阅读
也想出现在这里? 联系我们

开源,免费,强大的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文件,请放在相应的位置。

本站声明:
本站所有资源来源于网络,分享目的仅供大家学习和交流!如若本站内容侵犯了原著者的合法权益,可联系邮箱976157886@qq.com进行删除。
自学哈专注于免费提供最新的分享知识、网络教程、网络技术的资源分享平台,好资源不私藏,大家一起分享!

自学哈网 » 「自学哈网」开源,免费,强大的PC/移动触摸滑动插件-Swiper
也想出现在这里? 联系我们
© 2022 Theme by - 自学哈网 & WordPress Theme. All rights reserved 浙ICP备2022016594号