0.0.5 • Published 7 years ago

joshua-picture-loader v0.0.5

Weekly downloads
4
License
ISC
Repository
github
Last release
7 years ago

PictureLoader

Use the sessionStorage, loading pictures will first check whether there is no expired sessionStorage resources, if any, then directly from the local load; otherwise, request online resources.

tip:sessionStorage has a size limit, if the image size exceeds the limit, it will not be stored locally, still use online resources

initialize 1:insert to dom after load

step 1

<div class="preload" data-source="image/source.jpg"></div>

step 2

let loader = new PictureLoader({
  	className: 'preload',
});

initialize 2:load the image source only

let loaderQueue = new PictureLoader({
    sourceQueue: [
        'image/1.jpg',
        'image/2.jpg',
        'image/3.jpg',
        'image/4.jpg',
        'image/5.jpg',
    ],
});

start to load

loader.load();

html attribute

namedescription
data-sourceimage source to load
data-bgwhether load as background image

initialize options

className & sourceQueue two choose one

nametypedefault valuedescription
classNamestringpreloaddetermine the class name of loader element
sourceQueuearray[]source collection to load
loadOnefunctionnulltrigger when load one image
loadAllfunctionnulltrigger when load all images

static property

nametypedefault valuedescription
dataNamestringdata-sourcedetermine which attribute to set the source
flagBgstringdata-bgdetermine whether to load as background image
survivalTimenumber (ms)60000survival time of cache
useStoragebooleantrue on desktop browser except IE. Other platform will be falsewhether use sesstion storage or not
0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago