响应式高性能内容滚动条 SuperMarquee

  • 源码大小:173.31KB
  • 所需积分:1积分
  • 源码编号:19JP-3429
  • 浏览次数:724次
  • 最后更新:2023年06月12日
  • 所属栏目:动画
本站默认解压密码:19jp.com 或 19jp_com

简介

字幕滚动是20多年前网络开发人员发现的一种众所周知的效果。它最初被用作一种创造性的技术,用于引人注目的文本和图形展示。

SuperMarquee是一个JavaScript插件,它可以为您提供一个高度美观的动画内容滚动器,类似于传统的字幕滚动效果。它由纯CSS和JS组成,不包含任何图像,使其具有充分的响应能力和高性能。

特征:

  • 可与Vanilla JavaScript、jQuery、React、Angular、Vue和Web组件配合使用。
  • 超级平滑的过渡效果。
  • 3D转换,帮助您创建《星球大战》简介文本效果。
  • 水平和垂直滚动。
  • 自定义动画速度。
  • 悬停时自动播放和暂停。
  • RTL支持。
  • 根据GPLv3许可证获得许可。

如何使用它:

1.安装和下载。

  1. # NPM
  2. $ npm i sp-supermarquee

2.导入SuperMarquee。

  1. // As an ES module
  2. import SuperMarquee from "sp-supermarquee";
  1. <!-- Vanilla JS -->
  2. <script src="/path/to/dist/SuperMarquee.min.js"></script>
  1. <!-- jQuery -->
  2. <script src="/path/to/cdn/jquery.min.js"></script>
  3. <script src="/path/to/dist/jquery.supermarquee.min.js"></script>
  1. <!-- Web Component -->
  2. <script src="/path/to/dist/SuperMarqueeWC.min.js"></script>

3.创建一个容器来容纳滚动条(Vanilla JS&jQuery版本)。

  1. <div id="supermarquee"></div>

4.初始化SuperMarquee并在JavaScript中定义内容,如下所示:

  1. // Vanilla JavaScript
  2. const myScroller = new SuperMarquee(
  3. document.getElementById( "supermarquee" ),
  4. {
  5. "content" : "Text To Scroll..."
  6. }
  7. );
  8.  
  9. // jQuery
  10. $('#supermarquee').supermarquee({
  11. "content" : "Text To Scroll..."
  12. });

5.或者将其用作web组件。

  1. <super-marquee
  2. content="Text To Scroll..."
  3. ... more props here ...
  4. >
  5. </super-marquee>

6.要自定义滚动条,请传递一个具有以下选项的对象:

  1. $('#supermarquee').supermarquee({
  2.  
  3. // or "vertical"
  4. "type" : "horizontal",
  5.  
  6. // "superslow", "slow"
  7. // "fast", "superfast"
  8. "speed" : "medium",
  9.  
  10. // "ltr": left to right
  11. // "rtl": right to left
  12. // "btt": bottom to top
  13. // "ttb": top to bottom
  14. "direction" : "ltr",
  15.  
  16. // "gapped", "pingpong"
  17. "mode" : "continuous",
  18.  
  19. // delay in ms for pingping mode
  20. "pingPongDelay" : 2000,
  21.  
  22. // "fixedTop", "fixedBottom"
  23. "position" : "custom",
  24.  
  25. // e.g. "{\"z\": 400, \"rotateX\" : 30}", where
  26. // "z" : number, perspective in pixel, default: "none"
  27. // "originX" : number, originX in %, default: 50
  28. // "originY" : number, originY in %, default: 50
  29. // "rotateX" : number, transform:rotateX in degree, default: 0
  30. // "rotateY" : number, transform-rotateY in degree, default: 0
  31. // "rotateZ" : number, transform-rotateZ in degree, default: 0
  32. "perspective" : null,
  33.  
  34. // pause on hover
  35. "pauseonhover" : false,
  36.  
  37. // auto start on init
  38. "autostart" : true,
  39.  
  40. // custom easing function
  41. "easing" : false,
  42.  
  43. // scrolling text
  44. "content" : "SuperMarquee By SuperPlug.in Is Super !!!",
  45.  
  46. // any character appended to the content
  47. "spacer" : null,
  48. });

7.您也可以通过数据选项属性:

  1. <div
  2. id="supermarquee"
  3. data-type="horizontal"
  4. data-speed="medium"
  5. data-content="Text To Scroll">
  6. </div>

8.API方法。

  1. // play & resume the scroller
  2. myScroller.play();
  3.  
  4. // pause the scroller
  5. myScroller.pause();
  6.  
  7. // set content
  8. myScroller.setScrollContent(content);
  9.  
  10. // set animation speed
  11. myScroller.setScrollSpeed(speed);
  12.  
  13. // false|"0" means disabled, true|"1" means enabled
  14. myScroller.setPauseOnHover(String|Bool);
  15.  
  16. // the perspective settings as serialized JSON string.
  17. myScroller.setPerspective(perspective);
  18.  
  19. // destroy the instance
  20. myScroller.destroy();

更新日志:

2022-08-15

  • 2.0版本

2022-06-30

  • v1.4.2:修复了Bug

2022-06-29

  • v1.4.1:添加RSS提要模板逻辑

2022-04-01

  • 第1.3版

2022-03-30

  • 已修复配置设置中的错误

预览截图