Skip to content

Commit ae0804c

Browse files
committed
patch for lower version of IE
1 parent e9b1377 commit ae0804c

File tree

5 files changed

+140
-906
lines changed

5 files changed

+140
-906
lines changed

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,87 @@
11
# vue-l-lazyload
22

3+
> A lazyload plugin for Vue.js v2.x+.
4+
5+
### Pull requests are welcome :)
6+
7+
## License
8+
LGPL-V3
9+
[![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](http://www.gnu.org/licenses/lgpl-3.0)
10+
11+
## Features
12+
13+
- No extra dependencies except Vue
14+
- Progressive configuration
15+
- Flexible events to trigger loading
16+
- Lazyload as src attribute and background image are supported
17+
- Performance boost by event delegation and passive event listener if it's available
18+
19+
## Installation
20+
21+
[![vue-l-lazyload](https://nodei.co/npm/vue-l-carousel.png)](https://npmjs.org/package/vue-l-lazyload)
22+
23+
`npm install vue-l-lazyload`
24+
25+
## Usage
26+
### A simple way:
27+
```javascript
28+
import { VueLLazyload } from 'v-l-lazyload';
29+
Vue.use(VueLLazyload, {
30+
events: 'scroll'
31+
});
32+
```
33+
```html
34+
<img lazy="xxx.png">
35+
```
36+
### A more configurable way:
37+
```javascript
38+
import { VueLLazyload } from 'v-l-lazyload';
39+
Vue.use(VueLLazyload, config);
40+
```
41+
```html
42+
<lazy-ref ref="lazyRef" opts="config">
43+
<img lazy="{src:xxx.png, ref:'lazyRef'}">
44+
</lazy-ref>
45+
```
46+
47+
## Config
48+
<table class="table table-bordered table-striped">
49+
<thead>
50+
<tr>
51+
<th style="width: 100px;">Name</th>
52+
<th style="width: 50px;">Type</th>
53+
<th style="width: 50px;">Default</th>
54+
<th>Description</th>
55+
</tr>
56+
</thead>
57+
<tbody>
58+
</tobdy>
59+
</table>
60+
61+
## Directives
62+
### v-lazy
63+
#### value
64+
<table class="table table-bordered table-striped">
65+
<thead>
66+
<tr>
67+
<th style="width: 50px;">Type</th>
68+
<th>Description</th>
69+
</tr>
70+
</thead>
71+
<tbody>
72+
<tr>
73+
<td>String or Object</td>
74+
<td>
75+
If the value is an Object, it has the same spec as config.
76+
If the value is a String, it will be used as `src` of config
77+
</td>
78+
</tr>
79+
</tbody>
80+
</table>
81+
82+
## Components
83+
### lazy-ref
84+
85+
## Well, what's next?
86+
- More options for configuration
87+
- Supplements of test cases

demo/src/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
img {
88
width: 200px;
99
height: 200px;
10+
display: inline-block;
1011
}
1112
1213
.lazy-loading {

src/lazy.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ export function LazyClass(scope) {
198198
else {
199199
// inherit parent LazyLoader's options
200200
const $rootLazy = scope.$lazy;
201-
opts = Object.assign({
201+
opts = {
202202
parent: $rootLazy,
203-
}, parent && parent.opts || $rootLazy.opts, {
203+
...(parent && parent.opts || $rootLazy.opts),
204204
...opts,
205-
});
205+
};
206206
}
207207

208208
const {
@@ -259,8 +259,9 @@ export function LazyClass(scope) {
259259
preloadRatio = me.opts.preloadRatio,
260260
isWin = parentEl === win,
261261
parentElOffset = isWin ? {
262-
left: win.scrollX,
263-
top: win.scrollY,
262+
// IE, I'm looking at you
263+
left: win.pageXOffset,
264+
top: win.pageYOffset,
264265
width: win.innerWidth,
265266
height: win.innerHeight,
266267
} : offset(parentEl),

src/util.js

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,55 @@ function off(element, ev, callback) {
5555
}
5656
}
5757

58-
function addClass(element, className) {
59-
element.classList.add(className);
58+
function className(element, value) {
59+
var klass = element.className || '',
60+
svg = klass && klass.baseVal !== undefined;
61+
62+
if (value === undefined) return svg ? klass.baseVal : klass;
63+
if (svg) {
64+
klass.baseVal = value;
65+
}
66+
else {
67+
element.className = value;
68+
}
6069
}
6170

62-
function removeClass(element, className) {
63-
if (isStr(className)) {
64-
element.classList.remove(className);
71+
function addClass(element, classname) {
72+
const classList = element.classList;
73+
if (classList) {
74+
classList.add(classname);
75+
}
76+
else {
77+
const cls = className(element).split(' '),
78+
map = {};
79+
each(cls, (klass) => {
80+
map[klass] = true;
81+
});
82+
83+
if (!map[classname]) {
84+
className(element, cls.join(' ') + classname);
85+
}
86+
}
87+
}
88+
89+
function classRE(name) {
90+
return new RegExp(`(^|\\s)${name}(\\s|$)`);
91+
}
92+
93+
function removeClass(element, classname) {
94+
if (isStr(classname)) {
95+
const classList = element.classList;
96+
if (classList) {
97+
classList.remove(classname);
98+
}
99+
// IE, I'm looking at you again
100+
else {
101+
const cls = className(element);
102+
className(element, trim(cls.replace(classRE(classname), ' ')));
103+
}
65104
}
66-
else if (isArr(className)) {
67-
each(className, c => removeClass(element, c));
105+
else if (isArr(classname)) {
106+
each(classname, c => removeClass(element, c));
68107
}
69108
}
70109

0 commit comments

Comments
 (0)