-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: scrollToView not working properly if images exist
Closes: #351
- Loading branch information
Kang Cheng
committed
Dec 23, 2018
1 parent
6ac7bac
commit 3d0bfd6
Showing
4 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
export default (function () { | ||
let loadingImageCount = 0 | ||
const subscribers = [] | ||
|
||
function subscribe(cb) { | ||
subscribers.push(cb) | ||
} | ||
|
||
function unsubscribe(cb) { | ||
const index = subscribers.indexOf(cb) | ||
|
||
if (index !== -1) { | ||
subscribers.splice(index, 1) | ||
} | ||
} | ||
|
||
function notifyAllImagesComplete() { | ||
for (let i = 0; i < subscribers.length; i++) { | ||
subscribers[i]() | ||
} | ||
} | ||
|
||
function increaseLoadingImageCount() { | ||
loadingImageCount += 1 | ||
} | ||
|
||
function decreaseLoadingImageCount() { | ||
loadingImageCount -= 1 | ||
|
||
if (loadingImageCount === 0) { | ||
notifyAllImagesComplete() | ||
} | ||
} | ||
|
||
function cleanElement(ele) { | ||
ele.removeAttribute('onload') | ||
ele.removeAttribute('onerror') | ||
} | ||
|
||
function onLoad(ele) { | ||
cleanElement(ele) | ||
decreaseLoadingImageCount() | ||
} | ||
|
||
function onError(ele) { | ||
cleanElement(ele) | ||
decreaseLoadingImageCount() | ||
} | ||
|
||
function isAllImagesComplete() { | ||
return loadingImageCount === 0 | ||
} | ||
|
||
return { | ||
subscribe, | ||
unsubscribe, | ||
increaseLoadingImageCount, | ||
onLoad, | ||
onError, | ||
isAllImagesComplete | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './core' | ||
export * from './env' | ||
export * from '../router/util' | ||
export {default as image} from './image' |