Native javascript code example for implementing waterfall streaming on the Mobile End _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly shares examples of code for implementing waterfall streaming on mobile terminals using native js, if you are interested in waterfall stream layout, you can refer to the waterfall stream layout, which has become a very common way to present images on mobile devices such as PCs and mobile phones. Recently, I used "lazy loading", which is usually updated, because I usually use zepto. js for library files because of mobile development. Of course, it can also be used with jQuery.
The Code is as follows:

Function loadImgLazy (node) {var lazyNode = $ ('[node-type = imglazy]', node), mobileHeight, lazyOffSetHeight, tempHeight, currentNodeTop, imgObject, imgDataSrc, localUrl; localUrl = location. href; // get the mobileHeight of the visible area of the current browser =$ (window ). height (); return function (co) {var conf = {'loadfirst ': true, 'loadimg': true}; for (var item in conf) {if (item in co) {conf. item = co. item ;}} var that ={}; var _ this = {}; /*** [replaceImgSrc dynamically replaces src] * @ param {[type]} tempObject [description] * @ return {[type]} [description] */_ this. replaceImgSrc = function (tempObject) {var srcValue; $. each (tempObject, function (I, item) {imgObject = $ (item ). find ('img [data-lazysrc] '); imgObject. each (function (I) {imgDataSrc = $ (this ). attr ('data-lazysrc'); srcValue = $ (this ). attr ('src'); if (srcValue = '#') {if (imgDataSrc) {$ (this ). attr ('src', imgDataSrc); $ (this ). removeAttr ('data-lazysrc') ;}}}) ;};/*** check whether the imglazy node is displayed on the screen on the first screen, if yes, load the image * @ param {[type]} I) {currentNodeTop [description] * @ return {[type]} [description] */_ this. loadFirstScreen = function () {if (conf. loadfirst) {lazyNode. each (function (I) {currentNodeTop = $ (this ). offset (). top; if (currentNodeTop <mobileHeight + 800) {_ this. replaceImgSrc ($ (this) ;}}}; // after loading the first screen, load the image _ this according to the queue. loadImg = function () {if (conf. loadimg) {$ (window ). on ('scroll', function () {var imgLazyList = $ ('[node-type = imglazy]', node); for (var I = 0; I <5; I ++) {_ this. replaceImgSrc (imgLazyList. eq (I) ;}};};that = {replaceImgSrc: _ this. replaceImgSrc (), mobileHeight: mobileHeight, objIsEmpty: function (obj) {for (var item in obj) {return false;} return true;}, destory: function () {if (_ this) {$. each (_ this, function (I, item) {if (item & item. destory) {item. destory () ;}}); _ this = null ;}$ (window ). off ('scroll ') ;}}; return that ;};}

The above is all the content shared in this article. I hope it will be helpful for you to use javascript skillfully.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.