基于SVG路径运动的js轮播插件pathslider

所属分类:-

 13537  236  查看评论 (2)
分享到微信朋友圈
X
基于SVG路径运动的js轮播插件pathslider ie兼容10

path-slider.js

path-slider.js是一款基于SVG路径运动的js轮播插件。该js轮播插件可以根据指定的SVG路径,分布排列多个DOM元素,然后使这些DOM元素在SVG路径上执行轮播动画。

使用方法

在页面中引入anime.min.js和path-slider.js文件。

<script src="js/anime.min.js"></script>
<script src="js/path-slider.js"></script>

 HTML结构

一个最简单的基于SVG路径运动的js轮播效果的HTML结构如下。

<div class="container">
    <!-- Path Slider Container -->
    <div class="path-slider">
        <!-- SVG path to slide the items -->
        <svg width="460px" height="310px" viewBox="0 0 460 310">
            <path d="M 230 5 c -300 0 -300 300 0 300 c 300 0 300 -300 0 -300 Z" class="path-slider__path"></path>
        </svg>
        <!-- Slider items -->
        <a href="#chat" class="path-slider__item">
            <div class="item__circle"><svg class="item__icon"><use xlink:href="#chat"/></svg></div>
            <div class="item__title"><h2>Chat</h2></div>
        </a>
        <a href="#alarmclock" class="path-slider__item">
            <div class="item__circle"><svg class="item__icon"><use xlink:href="#alarmclock"/></svg></div>
            <div class="item__title"><h2>Alarm clock</h2></div>
        </a>
        <a href="#camera" class="path-slider__item">
            <div class="item__circle"><svg class="item__icon"><use xlink:href="#camera"/></svg></div>
            <div class="item__title"><h2>Camera</h2></div>
        </a>
        <a href="#envelope" class="path-slider__item">
            <div class="item__circle"><svg class="item__icon"><use xlink:href="#envelope"/></svg></div>
            <div class="item__title"><h2>Envelope</h2></div>
        </a>
        <a href="#lightbulb" class="path-slider__item">
            <div class="item__circle"><svg class="item__icon"><use xlink:href="#lightbulb"/></svg></div>
            <div class="item__title"><h2>Light bulb</h2></div>
        </a>
    </div>
</div>

可以看到有一条SVG path路径,在路径上有以及5个SVG做成的图案。效果图如下:

path-slider效果图

path-slider效果图

初始化插件

在页面DOM元素加载完毕之后,通过下面的方法来初始化该插件。

(function () {
 
    // Setting up the options
    var options = {
        startLength: 0, // start positioning the slider items at the beginning of the SVG path
        duration: 3000, // animation duration (used by anime.js)
        stagger: 15, // incrementally delays among items, producing an staggering effect
        easing: 'easeOutElastic', // easing function (used by anime.js)
        elasticity: 600, // elasticity factor (used by anime.js)
        rotate: true // This indicates that items should be rotated properly to match the SVG path curve
    };
 
    // Initialize the slider using our SVG path, items, and options
    new PathSlider('.path-slider__path', '.path-slider__item', options);
 
})();

其中,PathSlider()有三个参数,分别表示:

  • path:SVG路径。

  • items:DOM元素

  • options:配置参数。

配置参数

  • path-slider.js插件可用的配置参数有:

  • startLength:(float 或 'center') 开始定位元素的路径的长度。

  • activeSeparation:(float) 当前项与相邻项之间的距离。

  • paddingSeparation:(float) 在路径的开始和结束处的内间距。

  • duration、delay、easing和elasticity:这4个参数是anime.js插件的配置参数。

  • stagger:(ms) 每个项目动画之间的延迟。

  • begin:(function) 每一项开始动画后的回调函数。

  • end:(function) 每一项结束动画后的回调函数。

  • beginAll:(function) 所有项开始动画后的回调函数。

  • endAll:(function) 所有项结束动画后的回调函数。

  • blockUntilEnd:(boolean) 默认为false,如果设置为true,你需要等当前动画结束之后,才能选项另外的项。

  • clickSelection:(boolean) 默认为true,为每一个项添加click事件监听。

相关插件-

ichartjs-基于html5的图表组件

ichartjs 是一款基于HTML5的图形库。使用纯javascript语言, 利用HTML5的canvas标签绘制各式图形。 ichartjs致力于为您的应用提供简单、直观、可交互的体验级图表组件。是WEB/APP图表展示方面的解决方案 。如果你正在开发HTML5的应用,ichartjs正好适合您。 ichartjs目前支持饼图、环形图、折线图、面积图、柱形图、条形图。ichartjs是基于Apache License 2.0协议的开源项目。
 
 61266  392

基于ion.rangeslider.js 左右拖动滑块选择区间价格范围

基于ion.rangeslider.js 移动端左右拖动滑块选择区间价格范围js代码,可动态取值,用的更方便
 
 24704  323

jquery分步操作插件

jquery分步操作插件step.js,代码注释全修改方便。
 
 31842  329

iframe fixed失效问题兼容ios

iframe在安卓、ios中滚动,头部、底部也能固定。主要解决iframe在苹果手机iphone(ios)中滚动时头部与底部不能固定及滚动时出现卡顿的情况。本Demo演示iframe中固定父页面头部、底部,子页面正常滚动。兼容PC和移动端,尤其是苹果ios系统(如iphone手机)
 
 23474  313

讨论这个项目(2)回答他人问题或分享插件使用方法奖励jQ币 评论用户自律公约

    SunJiaJing90 0
    2019/8/22 17:30:18
    这个真不错 挺好看的
    回复
    寒水映月 0
    2019/8/22 15:26:02
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
取消回复