├── _config.yml ├── foxslider.gif ├── src ├── assets │ ├── slider1.jpg │ ├── slider2.jpg │ └── slider3.jpg ├── js │ ├── index.js │ └── base.js ├── css │ └── index.css └── index.html ├── LICENSE └── README.md /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /foxslider.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/forrestyuan/FoxSliderJS/HEAD/foxslider.gif -------------------------------------------------------------------------------- /src/assets/slider1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/forrestyuan/FoxSliderJS/HEAD/src/assets/slider1.jpg -------------------------------------------------------------------------------- /src/assets/slider2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/forrestyuan/FoxSliderJS/HEAD/src/assets/slider2.jpg -------------------------------------------------------------------------------- /src/assets/slider3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/forrestyuan/FoxSliderJS/HEAD/src/assets/slider3.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 ForrrestYuan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/js/index.js: -------------------------------------------------------------------------------- 1 | window.onload = function(){ 2 | //样式1 3 | var tp = new TouchPlugin({ 4 | sliderContainer:'.slider-identifier.slider-container', 5 | slider:'.slider-identifier .slider', 6 | slidePin:'.slider-identifier .slider-pin', 7 | sliderBar:'.slider-identifier .slide-bar', 8 | pinClassName:'on', 9 | pin:'.slider-identifier .pin', 10 | callback:function(e, dir, distance){} 11 | }); 12 | //样式2 13 | var tp = new TouchPlugin({ 14 | sliderContainer:'.slider-identifier2.slider-container', 15 | slider:'.slider-identifier2 .slider', 16 | slidePin:'.slider-identifier2 .slider-pin', 17 | sliderBar:'.slider-identifier2 .slide-bar', 18 | pinClassName:'on', 19 | pin:'.slider-identifier2 .pin', 20 | leftRightToggleBtn:{left:'.slider-identifier2 .leftArrowIcon',right:'.slider-identifier2 .rightArrowIcon'}, 21 | callback:function(e, dir, distance){} 22 | }); 23 | // 样式3 24 | var tp = new TouchPlugin({ 25 | sliderContainer:'.slider-identifier3.slider-container', 26 | slider:'.slider-identifier3 .slider', 27 | slidePin:'.slider-identifier3 .slider-pin', 28 | sliderBar:'.slider-identifier3 .slide-bar', 29 | pinClassName:'on', 30 | pin:'.slider-identifier3 .pin', 31 | leftRightToggleBtn:{left:'.slider-identifier3 .leftArrowIcon',right:'.slider-identifier3 .rightArrowIcon'}, 32 | callback:function(e, dir, distance){} 33 | }); 34 | } -------------------------------------------------------------------------------- /src/css/index.css: -------------------------------------------------------------------------------- 1 | html,body,div,img{margin: 0;padding: 0;} 2 | /*Icon */ 3 | .leftArrowIcon,.rightArrowIcon{display:inline-block;position: relative;width: 30px;height: 30px;cursor: pointer;padding:5px;} 4 | .leftArrowIcon::before,.leftArrowIcon::after,.rightArrowIcon::before,.rightArrowIcon::after{position: absolute;content: "";width: 20px;height: 3px;top:17px;left:8px;background-color: #fff; -webkit-transform-origin: left;-ms-transform-origin: left;transform-origin: left;} 5 | .rightArrowIcon::before,.rightArrowIcon::after { -webkit-transform-origin: right;-ms-transform-origin: right;transform-origin: right;} 6 | .leftArrowIcon::before,.rightArrowIcon::before{-webkit-transform: rotate(-45deg) translate(0,1px);-ms-transform: rotate(-45deg) translate(0,1px);transform: rotate(-45deg) translate(0,1px);} 7 | .leftArrowIcon::after,.rightArrowIcon::after{-webkit-transform: rotate(45deg) translate(0,1px);-ms-transform: rotate(45deg) translate(0,1px);transform: rotate(45deg) translate(0,1px);} 8 | 9 | 10 | 11 | .slider-container {position: relative;width: auto;height: auto;white-space: nowrap;overflow: hidden;} 12 | .slider {display: inline-block;width: 100%;height: 100%;} 13 | .slider * {user-select: none;} 14 | .slider img {width: 100%;} 15 | 16 | .slider:nth-child(n + 2) {margin-left: -5px;} 17 | .slide-bar {height: 100%;user-select: none;} 18 | .slider-pin {position: absolute;width: 100vw;left: 0;bottom: 15px;text-align: center;z-index: 100;} 19 | .slider-pin,.slider-pin * {user-select: none;} 20 | .slider-pin span {display: inline-block;margin: 0 5px;width: 10px;height: 10px;border-radius: 100%;cursor: pointer;color: transparent;background-color: white;} 21 | .slider-pin span.on {background-color: dodgerblue;} 22 | /* .slider-pin[data-type="img"] {} */ 23 | .slider-pin[data-type="img"] span{margin:0 10px 0 0;width:100px;height:50px;border-radius: 0;} 24 | .slider-pin[data-type="img"] span img{width:100px;height:50px;} 25 | .slider-pin[data-type="img"] span.on {border:solid 2px dodgerblue;} 26 | 27 | .left-right-btn .leftArrowIcon,.left-right-btn .rightArrowIcon{position: absolute;width:30px;height:30px;top:0;bottom:0;margin:auto;z-index: 2000;} 28 | .left-right-btn .leftArrowIcon{left:0;} 29 | .left-right-btn .rightArrowIcon{right:0;} 30 | .left-right-btn .leftArrowIcon:hover,.left-right-btn .rightArrowIcon:hover{background-color: gray;} 31 | 32 | @media only screen and (max-width:1240px){ 33 | .slider-pin[data-type="img"] span{margin:0 10px 0 0;width:50px;height:30px;border-radius: 0;} 34 | .slider-pin[data-type="img"] span img{width:50px;height:30px;} 35 | } 36 | @media only screen and (max-width:600px){ 37 | .leftArrowIcon,.rightArrowIcon{width: 20px;height: 20px;} 38 | .left-right-btn .leftArrowIcon,.left-right-btn .rightArrowIcon{width:15px;height:15px;} 39 | .left-right-btn .leftArrowIcon:hover,.left-right-btn .rightArrowIcon:hover{background-color:transparent;} 40 | .leftArrowIcon::before,.leftArrowIcon::after,.rightArrowIcon::before,.rightArrowIcon::after{width: 15px;height: 2px;top:10px;left:5px;} 41 | 42 | .slider-pin{bottom: 10px;} 43 | .slider-pin span,.slider-pin[data-type="img"] span{margin: 0 5px;width:5px;height:5px;border-radius: 100%;} 44 | .slider-pin[data-type="img"] span img{display: none;} 45 | .slider-pin[data-type="img"] span.on {border:none} 46 | } -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |number | 滚动位移 |
94 | | spinIndex | number | 轮播指标高亮下标 |
95 |
96 | ***
97 |
98 |
99 | ## setTranslate(domNode, conf, moveLen)
100 | 设置指定对象移动样式 (transform)
101 |
102 | **Kind**: global function
103 |
104 | | Param | Type | Description |
105 | | --- | --- | --- |
106 | | domNode | Object | 应用移动样式的对象 |
107 | | conf | Object | 配置对象(animateStyle: ease-in-out|linear|ease-in|ease; animateTime:number | 轮播图移动距离(切屏通过控制位移) |
109 | ***
110 |
111 |
112 |
113 | ### resize()
114 | 改变屏幕尺寸重置参数
115 |
116 | **Kind**: global function
117 | ***
118 |
119 |
120 |
121 | ### autoRun(time, initStep)
122 | 自动轮播
123 |
124 | **Kind**: global function
125 |
126 | | Param | Type | Description |
127 | | --- | --- | --- |
128 | | time | number | 轮播时间 |
129 | | initStep | number | spin下标 和下一屏 |
130 | ***
131 |
132 |
133 |
134 | ### judgeDir(curX, preX)
135 | 判断鼠标或触摸移动的方向
136 |
137 | **Kind**: global function
138 |
139 | | Param | Type | Description |
140 | | --- | --- | --- |
141 | | curX | number | 鼠标点击或开始触摸屏幕时的坐标X |
142 | | preX | numer | 鼠标移动或触摸移动时的坐标X |
143 | ***
144 |
145 |
146 |
147 | ### testTouchEvent()
148 | 检测当前设备支持的事件(鼠标点击移动和手触摸移动)
149 |
150 | **Kind**: global function
151 | ***
152 |
153 |
154 |
155 | ### mouseX(event)
156 | 获取鼠标横坐标位置
157 |
158 | **Kind**: global function
159 |
160 |
161 | | Param | Type | Description |
162 | | --- | --- | --- |
163 | | event | Event | 事件对象 |
164 |
165 | ***
166 |
167 |
168 | ### cancelBind(domNode)
169 | 取消绑定触摸或鼠标点击移动事件
170 |
171 | **Kind**: global function
172 |
173 | | Param | Type | Description |
174 | | --- | --- | --- |
175 | | domNode | Object | 需要被取消绑定事件节点对象 |
176 | ***
177 |
178 |
179 |
180 | ### reBindTouchEvent(domNode, callback, isUnbind)
181 | 重新绑定触摸事件
182 |
183 | **Kind**: global function
184 |
185 | | Param | Type | Description |
186 | | --- | --- | --- |
187 | | domNode | Object | 需要被绑定事件节点对象 |
188 | | callback | function | 回调方法 |
189 | | isUnbind | boolean | 是否取消绑定 |
190 | ***
191 |
192 |
193 |
194 | ### removeClsName(nodeList, clsName)
195 | 移除节点的样式类名
196 |
197 | **Kind**: global function
198 |
199 | | Param | Type | Description |
200 | | --- | --- | --- |
201 | | nodeList | Array | 被移除样式的节点数组 |
202 | | clsName | string | 移除的样式类名称 |
203 | ***
204 |
205 |
206 |
207 | ### setClsName(node, clsName)
208 | 添加样式
209 |
210 | **Kind**: global function
211 |
212 | | Param | Type | Description |
213 | | --- | --- | --- |
214 | | node | Object | 添加类名的节点 |
215 | | clsName | string | 样式类名 |
216 | ***
217 |
218 |
219 |
220 | ### bindSpinClick()
221 | 点击轮播spin 切换屏
222 |
223 | **Kind**: global function
224 | ***
225 |
226 |
227 | ### bindLeftRightBtnClick()
228 | 点击左右按钮切换屏
229 |
230 | **Kind**: global function
231 | ***
232 |
233 |
234 | ## checkTargetByCls(domNode, clsName)
235 | 通过检测dom节点是否包含某个样式名来判断是否属于目标target
236 |
237 | **Kind**: global function
238 |
239 | | Param | Type |
240 | | --- | --- |
241 | | domNode | Object |
242 | | clsName | string |
243 | ***
244 |
245 |
246 | ### bindTouchEvent(domNode, callback, isUnbind)
247 | **Kind**: global function
248 |
249 | | Param | Type | Description |
250 | | --- | --- | --- |
251 | | domNode | Object | 绑定事件的代理对象 |
252 | | callback | function | 回调方法 |
253 | | isUnbind | boolean | 是否取消绑定 |
254 | ***
255 |
--------------------------------------------------------------------------------
/src/js/base.js:
--------------------------------------------------------------------------------
1 | var getEle = (function (obj) {
2 | return function (selector, isSingle) {
3 | return isSingle ? obj.querySelector(selector) : obj.querySelectorAll(selector);
4 | }
5 | })(window.document);
6 |
7 | /**
8 | * @param {Object} obj 参数配置,参数的值为 样式名 即可。以下的argument配置在obj对象中
9 | * @argument sliderContainer 轮播图最顶层父容器
10 | * @argument sliderBar 轮播图Item的父容器
11 | * @argument slider 轮播图Item
12 | * @argument sliderPin 轮播图小圆点的容器
13 | * @argument pin 轮播图高亮小圆点
14 | * @argument pinClassName 高亮小圆点时的样式,可自定义样式名
15 | * @argument leftRightToggleBtn {left:'.left', rigth:'right'}
16 | *
17 | */
18 | function TouchPlugin(obj) {
19 | /**
20 | * @desc 初始化函数
21 | */
22 | this.init = function () {
23 | //配置信息
24 | this.sliderContainer = getEle(obj.sliderContainer);
25 | this.slider = getEle(obj.slider);
26 | this.sliderPin = getEle(obj.sliderPin);
27 | this.pinClassName = obj.pinClassName || "on";
28 | this.sliderBar = getEle(obj.sliderBar);
29 | this.pin = getEle(obj.pin);
30 | this.leftToggleBtn = ("leftRightToggleBtn" in obj) ? getEle(obj.leftRightToggleBtn.left):null;
31 | this.rightToggleBtn = ("leftRightToggleBtn" in obj) ? getEle(obj.leftRightToggleBtn.right):null;
32 | this.autoScrollInterval = null;
33 | this.hasMove = false;
34 | //取消图片拖拽默认事件
35 | for (var i = 0; i < this.slider.length; i++) {
36 | this.slider[i].querySelector('img').setAttribute('ondragstart', 'return false');
37 | }
38 | //改变屏幕尺寸会刷新的配置参数
39 | this.refreshParam();
40 | //事件绑定
41 | this.testTouchEvent();
42 | this.bindTouchEvent(this.sliderContainer[0], obj.callback, false);
43 | this.resize();
44 | this.bindSpinClick();
45 | ;!!(this.leftToggleBtn && this.rightToggleBtn) ? this.bindLeftRightBtnClick() : false;
46 | this.autoRun();
47 | }
48 |
49 | /**
50 | * @desc 设置指定对象移动样式 (transform)
51 | * @param {Object} domNode 应用移动样式的对象
52 | * @param {Object} conf 配置对象(animateStyle: ease-in-out|linear|ease-in|ease; animateTime: