Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the effect of infinitely loading adaptive screen waterfall stream pictures by js

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "js how to achieve unlimited load adaptive screen waterfall flow picture effect", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "js how to achieve unlimited load adaptive screen waterfall flow picture effect" bar!

Infinitely load adaptive screen waterfall stream picture effect

/ *

Put aside all kinds of messy algorithms of waterfall flow layout, waterfall flow based on masonry is very simple, and by extending animate, waterfall flow layout can be achieved, such as sloshing, pinball and so on.

Masonry has a lot of parameters. I've annotated the commonly used parameters here.

, /

$(function () {)

/ * Waterfall flow starts * /

Var container = $('.waterfull ul')

Var loading=$ ('# imloading')

/ / initialize loading status

Loading.data ("on", true)

/ * determine the maximum layout width of the waterfall flow, which is 1280 meters /

Function tores () {

Var tmpWid=$ (window) .width ()

If (tmpWid > 1280) {

TmpWid=1280

} else {

Var column=Math.floor (tmpWid/320)

TmpWid=column*320

}

$('.waterfull') .width (tmpWid)

}

Tores ()

$(window) .resize (function () {

Tores ()

});

Container.imagesLoaded (function () {

Container.masonry ({

ColumnWidth: 320

ItemSelector: '.item'

IsFitWidth: whether true,// automatically adapts to the default false based on browser window size

IsAnimated: whether true,// uses jquery animation for remake

IsRTL:false,// sets how the layout is arranged, that is, whether the bricks are arranged from left to right or from right to left when positioning bricks. The default is false, that is, from left to right

IsResizable: whether true,// automatically lays out the default true

AnimationOptions: {

Duration: 800

Easing: 'easeInOutBack',// if you refer to jQeasing, you can add corresponding dynamic animation effects here. If there is no reference to delete this line, the default is uniform speed change.

Queue: whether false// is a queue to fill the waterfall flow from one point

}

});

});

/ * simulate the data obtained from the background * /

Var sqlJson= [{'title':' Falls flow is really a matter of several functions!' Intro':' revealed that Suarez bit again. Ronaldo doesn't have Nemal Shuai. If Messi doesn't win the championship this year, you can go to Thailand. I bought Argentina to win the lottery, but if I lose, I can't go.' , 'src':'images/one.jpg','writer':' title', 'date':'2 hours ago', 'looked':321}, {' title':' Falls flow is actually a matter of several functions!' Intro':' revealed that Suarez bit again. Cristiano Ronaldo doesn't have Nemal Shuai. If Messi doesn't win the championship this year, you can go to Thailand. I bought Argentina to win the lottery, but if I lose, I can't go.' , 'src':'images/demo2.jpg','writer':' title', 'date':'2 hours ago', 'looked':321}, {' title':' Falls flow is actually a matter of several functions!' Intro':' revealed that Suarez bit again. Cristiano Ronaldo doesn't have Nemal Shuai. If Messi doesn't win the championship this year, you can go to Thailand. I bought Argentina to win the lottery, but if I lose, I can't go.' , 'src':'images/p1.jpg','writer':' title', 'date':'2 hours ago', 'looked':321}, {' title':' Falls flow is actually a matter of several functions!' Intro':' revealed that Suarez bit again. Cristiano Ronaldo doesn't have Nemal Shuai. If Messi doesn't win the championship this year, you can go to Thailand. I bought Argentina to win the lottery, but if I lose, I can't go.' , 'src':'images/p1.jpg','writer':' title', 'date':'2 hours ago', 'looked':321}]

/ * We should have requested sqljson-like data from the background through ajax and populated it. Here we use sqlJson to simulate the data * /

$(window) .subscription (function () {

If (! loading.data ("on")) return

/ / calculate the largest distance from the top of all the waterfall flow blocks, and then make the ajax request when the scroll bar scrolls. There are many ways to list only the simplest one and the easiest to understand.

Var itemNum=$ ('# waterfull'). Find ('.item'). Length

Var itemArr= []

ItemArr [0] = $('# waterfull'). Find ('.item') .eq (itemNum-1). Offset (). Top+$ ('# waterfull'). Find ('.item') .eq (itemNum-1) [0] .offsetHeight

ItemArr [1] = $('# waterfull'). Find ('.item') .eq (itemNum-2). Offset (). Top+$ ('# waterfull'). Find ('.item') .eq (itemNum-1) [0] .offsetHeight

ItemArr [2] = $('# waterfull'). Find ('.item') .eq (itemNum-3). Offset (). Top+$ ('# waterfull'). Find ('.item') .eq (itemNum-1) [0] .offsetHeight

Var maxTop=Math.max.apply (null,itemArr)

If (maxTop30) {

Loading.text ('that's all!')

} else {

Var html= ""

For (var i in sqlJson) {

Html+= "

"

Html+= "" + sqlJson [I] .title + ""

Html+= "" + sqlJson [I] .intro + "

"

Html+= "" + sqlJson [I] .looked + "browse"

Html+= "" + sqlJson [I] .writer + "" + sqlJson [I] .date + "By"

}

/ * simulate ajax request data delay 800ms * /

Var time=setTimeout (function () {

$(html) .find ('img') .each (function (index) {

LoadImage ($(this) .attr ('src'))

})

Var $newElems = $(html) .css ({opacity: 0}) .appendto (container)

$newElems.imagesLoaded (function () {

$newElems.animate ({opacity: 1}, 800)

Container.masonry ('appended', $newElems,true)

Loading.data (on, true). FadeOut ()

ClearTimeout (time)

});

}, 800)

}

}) (sqlJson)

}

});

Function loadImage (url) {

Var img = new Image ()

/ / create an Image object to realize the pre-download of images

Img.src = url

If (img.complete) {

Return img.src

}

Img.onload = function () {

Return img.src

}

}

LoadImage ('images/one.jpg')

/ * item hover effect * /

Var rbgB= ['# 71D3F5', 'F0C179,' F28386, '8BD38B']

$('# waterfull'). On ('mouseover','.item',function () {

Var random=Math.floor (Math.random () * 4)

$(this) .stop (true) .animate ({'backgroundColor':rbgB [random]}, 1000)

});

$('# waterfull'). On ('mouseout','.item',function () {

$(this) .stop (true) .animate ({'backgroundColor':'#fff'}, 1000)

});

})

Hand-in-hand teaching you to use css3 to create loading animation (2)

The previous standard of HTML 5 did not allow direct cross-domain communication due to browser security.

688 browsing

Title

Two hours ago, By

Hand-in-hand teaching you to use css3 to create loading animation (2)

The previous standard of HTML 5 did not allow direct cross-domain communication due to browser security.

688 browsing

Title

Two hours ago, By

Hand-in-hand teaching you to use css3 to create loading animation (2)

The previous standard of HTML 5 did not allow direct cross-domain communication due to browser security.

688 browsing

Title

Two hours ago, By

Hand-in-hand teaching you to use css3 to create loading animation (2)

The previous standard of HTML 5 did not allow direct cross-domain communication due to browser security.

688 browsing

Title

Two hours ago, By

Hand-in-hand teaching you to use css3 to create loading animation (2)

The previous standard of HTML 5 did not allow direct cross-domain communication due to browser security.

688 browsing

Title

Two hours ago, By

Hand-in-hand teaching you to use css3 to create loading animation (2)

The previous standard of HTML 5 did not allow direct cross-domain communication due to browser security.

688 browsing

Title

Two hours ago, By

Hand-in-hand teaching you to use css3 to create loading animation (2)

The previous standard of HTML 5 did not allow direct cross-domain communication due to browser security.

688 browsing

Title

Two hours ago, By

Hand-in-hand teaching you to use css3 to create loading animation (2)

The previous standard of HTML 5 did not allow direct cross-domain communication due to browser security.

688 browsing

Title

Two hours ago, By

Hand-in-hand teaching you to use css3 to create loading animation (2)

The previous standard of HTML 5 did not allow direct cross-domain communication due to browser security.

688 browsing

Title

Two hours ago, By

Hand-in-hand teaching you to use css3 to create loading animation (2)

The previous standard of HTML 5 did not allow direct cross-domain communication due to browser security.

688 browsing

Title

Two hours ago, By

Hand-in-hand teaching you to use css3 to create loading animation (2)

The previous standard of HTML 5 did not allow direct cross-domain communication due to browser security.

688 browsing

Title

Two hours ago, By

The material is loading.

Thank you for reading, the above is "js how to achieve unlimited load adaptive screen waterfall flow picture effect" content, after the study of this article, I believe you on js how to achieve unlimited load adaptive screen waterfall stream picture effect of this problem has a deeper understanding, the specific use of the need for everyone to practice and verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report