swiper-mouseover 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +63 -0
- package/package.json +36 -0
- package/swiper-mouseover.css +16 -0
- package/swiper-mouseover.js +63 -0
- package/swiper-mouseover.min.css +6 -0
- package/swiper-mouseover.min.js +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Pavel Romanov
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Swiper-Mouseover
|
|
2
|
+
Small plugin for [Swiper](https://github.com/nolimits4web/swiper).
|
|
3
|
+
Adds the ability to automatically change slides with mouse movement.
|
|
4
|
+
|
|
5
|
+
## Demo
|
|
6
|
+
:point_right: https://codesandbox.io/p/sandbox/swiper-mouseover-q9h6cf
|
|
7
|
+
|
|
8
|
+
## How use
|
|
9
|
+
|
|
10
|
+
#### 1. Include Swiper
|
|
11
|
+
See https://swiperjs.com/get-started#installation
|
|
12
|
+
|
|
13
|
+
#### 2. Include Mouseover:
|
|
14
|
+
Pull-in a latest version with NPM:
|
|
15
|
+
```
|
|
16
|
+
npm i swiper-mouseover
|
|
17
|
+
```
|
|
18
|
+
and provide <link> to the required:
|
|
19
|
+
```html
|
|
20
|
+
<link href="/path/to/swiper-mouseover.min.css" rel="stylesheet">
|
|
21
|
+
<script src="/path/to/swiper-mouseover.min.js"></script>
|
|
22
|
+
```
|
|
23
|
+
or use CDN:
|
|
24
|
+
```html
|
|
25
|
+
<link href="https://cdn.jsdelivr.net/gh/fibit/swiper-mouseover@main/swiper-mouseover.min.css" rel="stylesheet">
|
|
26
|
+
<script src="https://cdn.jsdelivr.net/gh/fibit/swiper-mouseover@main/swiper-mouseover.min.js"></script>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#### 3. Add Swiper HTML Layout:
|
|
30
|
+
```html
|
|
31
|
+
<div class="swiper mySwiper">
|
|
32
|
+
<div class="swiper-wrapper">
|
|
33
|
+
<div class="swiper-slide">Slide 1</div>
|
|
34
|
+
<div class="swiper-slide">Slide 2</div>
|
|
35
|
+
<div class="swiper-slide">Slide 3</div>
|
|
36
|
+
...
|
|
37
|
+
</div>
|
|
38
|
+
<div class="swiper-mouseover"></div>
|
|
39
|
+
</div>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
#### 4. Initialize Swiper with Mouseover:
|
|
43
|
+
```js
|
|
44
|
+
const swiper = new Swiper('.mySwiper', {
|
|
45
|
+
modules: [MouseoverPlugin],
|
|
46
|
+
mouseover: {
|
|
47
|
+
el: '.swiper-mouseover'
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Key Features
|
|
53
|
+
- Native Swiper Integration: Works like other official Swiper modules;
|
|
54
|
+
- Touch Device Detection: Automatically disabled on touchscreen devices;
|
|
55
|
+
- Customizable: Specify your own mouseover element selector;
|
|
56
|
+
- Lightweight: Adds minimal overhead to your bundle;
|
|
57
|
+
- Accessible: Preserves standard Swiper functionality.
|
|
58
|
+
|
|
59
|
+
## Behavior Notes
|
|
60
|
+
- The plugin creates transparent overlay layers that intercept mouse events;
|
|
61
|
+
- Standard Swiper controls remain visible but non-interactive when mouseover is active;
|
|
62
|
+
- Slides automatically return to the first position when mouse leaves the container;
|
|
63
|
+
- Fully compatible with other Swiper plugins and features.
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "swiper-mouseover",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Mouseover plugin for Swiper",
|
|
5
|
+
"files": [
|
|
6
|
+
"swiper-mouseover.js",
|
|
7
|
+
"swiper-mouseover.min.js",
|
|
8
|
+
"swiper-mouseover.css",
|
|
9
|
+
"swiper-mouseover.min.css"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "echo \"Tests skipped\" && exit 0"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/fibit/swiper-mouseover.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"swiper",
|
|
20
|
+
"swiper-plugin",
|
|
21
|
+
"slider",
|
|
22
|
+
"carousel",
|
|
23
|
+
"mouseover",
|
|
24
|
+
"mouse-navigation",
|
|
25
|
+
"hover-navigation"
|
|
26
|
+
],
|
|
27
|
+
"author": "Pavel Romanov",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/fibit/swiper-mouseover/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/fibit/swiper-mouseover#readme",
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"swiper": ">=11.0.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swiper-Mouseover v2.0.1 for Swiper (https://github.com/fibit/swiper-mouseover)
|
|
3
|
+
* Author Pavel Romanov
|
|
4
|
+
* Released under the MIT License
|
|
5
|
+
*/
|
|
6
|
+
.swiper-mouseover {
|
|
7
|
+
display: flex;
|
|
8
|
+
position: absolute;
|
|
9
|
+
inset: 0;
|
|
10
|
+
z-index: 11;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.swiper-mouseover-layer {
|
|
14
|
+
flex: 1 0 0%;
|
|
15
|
+
height: 100%;
|
|
16
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swiper-Mouseover v2.0.1 for Swiper (https://github.com/fibit/swiper-mouseover)
|
|
3
|
+
* Author Pavel Romanov
|
|
4
|
+
* Released under the MIT License
|
|
5
|
+
*/
|
|
6
|
+
function MouseoverPlugin({ swiper, extendParams, on }) {
|
|
7
|
+
extendParams({
|
|
8
|
+
mouseover: {
|
|
9
|
+
el: null
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const initMouseover = () => {
|
|
14
|
+
const { el } = swiper.params.mouseover;
|
|
15
|
+
|
|
16
|
+
if (!el) return;
|
|
17
|
+
|
|
18
|
+
const mouseoverEl = typeof el === 'string'
|
|
19
|
+
? document.querySelector(el)
|
|
20
|
+
: el;
|
|
21
|
+
|
|
22
|
+
if (!mouseoverEl) return;
|
|
23
|
+
|
|
24
|
+
if ('ontouchstart' in window) {
|
|
25
|
+
mouseoverEl.remove();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
mouseoverEl.innerHTML = '';
|
|
30
|
+
|
|
31
|
+
mouseoverEl.querySelectorAll('.swiper-mouseover-layer').forEach(el => {
|
|
32
|
+
el.removeEventListener('mouseover', handleMouseOver);
|
|
33
|
+
el.removeEventListener('mouseout', handleMouseOut);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < swiper.snapGrid.length; i++) {
|
|
37
|
+
const layer = document.createElement('div');
|
|
38
|
+
layer.className = 'swiper-mouseover-layer';
|
|
39
|
+
layer.setAttribute('data-swiper-slide-index', i);
|
|
40
|
+
mouseoverEl.appendChild(layer);
|
|
41
|
+
layer.addEventListener('mouseover', handleMouseOver);
|
|
42
|
+
layer.addEventListener('mouseout', handleMouseOut);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function handleMouseOver() {
|
|
46
|
+
const slideIndex = parseInt(this.getAttribute('data-swiper-slide-index'));
|
|
47
|
+
swiper.slideTo(slideIndex, swiper.params.speed);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function handleMouseOut() {
|
|
51
|
+
swiper.slideTo(0, swiper.params.speed);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
on('afterInit', initMouseover);
|
|
56
|
+
on('destroy', () => {
|
|
57
|
+
const { el } = swiper.params.mouseover;
|
|
58
|
+
if (el) {
|
|
59
|
+
const mouseoverEl = typeof el === 'string' ? document.querySelector(el) : el;
|
|
60
|
+
if (mouseoverEl) mouseoverEl.remove();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swiper-Mouseover v2.0.1 for Swiper (https://github.com/fibit/swiper-mouseover)
|
|
3
|
+
* Author Pavel Romanov
|
|
4
|
+
* Released under the MIT License
|
|
5
|
+
*/
|
|
6
|
+
.swiper-mouseover{display:flex;position:absolute;inset:0;z-index:11}.swiper-mouseover-layer{flex:1 0 0%;height:100%}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swiper-Mouseover v2.0.1 for Swiper (https://github.com/fibit/swiper-mouseover)
|
|
3
|
+
* Author Pavel Romanov
|
|
4
|
+
* Released under the MIT License
|
|
5
|
+
*/
|
|
6
|
+
function MouseoverPlugin({swiper:e,extendParams:t,on:o}){t({mouseover:{el:null}});o("afterInit",(()=>{const{el:t}=e.params.mouseover;if(!t)return;const o="string"==typeof t?document.querySelector(t):t;if(o)if("ontouchstart"in window)o.remove();else{o.innerHTML="",o.querySelectorAll(".swiper-mouseover-layer").forEach((e=>{e.removeEventListener("mouseover",r),e.removeEventListener("mouseout",s)}));for(let t=0;t<e.snapGrid.length;t++){const e=document.createElement("div");e.className="swiper-mouseover-layer",e.setAttribute("data-swiper-slide-index",t),o.appendChild(e),e.addEventListener("mouseover",r),e.addEventListener("mouseout",s)}}function r(){const t=parseInt(this.getAttribute("data-swiper-slide-index"));e.slideTo(t,e.params.speed)}function s(){e.slideTo(0,e.params.speed)}})),o("destroy",(()=>{const{el:t}=e.params.mouseover;if(t){const e="string"==typeof t?document.querySelector(t):t;e&&e.remove()}}))}
|