Giter Site home page Giter Site logo

hadryan / jquery.waterfall Goto Github PK

View Code? Open in Web Editor NEW

This project forked from linzap/jquery.waterfall

0.0 2.0 0.0 64 KB

Waterfall, cross-browser typesetting on the web with jQuery

Home Page: http://linzap.github.io/waterfall/loadmore.html

License: Other

HTML 44.39% JavaScript 55.61%

jquery.waterfall's Introduction

jQuery.waterfall

Code Climate Join the chat at https://gitter.im/LinZap/jquery.waterfall

Waterfall is a simple and light jQuery plug-in, you can use it easily and fluently! Enjoy!!!

Alt text

Examples

If you want to WATERFALL div under #box

<!-- box is a container -->
<div id="box">
	<div>Card1</div>
	<div>Card2</div>
	<div>Card3</div>
	<div>Card4</div>
	<div>Card5</div>
</div>

Pick the target element

// waterfall have effect on #box
$(function(){
	$('#box').waterfall();
})

All div in #box will be showed in Waterfall as above.

More Examples

Installation

Just load jQuery library and then Waterfall library.

Basic

<!-- The jQuery library version >= 1.8 -->
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>;
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<!-- The core Waterfall library -->
<script src="//linzap.github.io/waterfall/waterfall-light.js"></script>

or download Waterfall starter kit to load the library which make loading speed faster.

Bower

bower install jquery.waterfall

Advanced usage

Here are some methods below, if you need better control !

Setting

var setting = {
	gap: 10,
	gridWidth: [0,400,600,800,1200],
	refresh: 500,
	scrollbottom : {
		ele: $('body'),
		endtxt : 'No More~~',
		gap: 300,
		callback: funciton(container){
			// do something
		}
	}
};
$(function(){
	$('box').waterfall(setting);
})

γ€€And more options if you like πŸ˜„

  • gap(int): distance between neighboring objects in pixels.
  • gridWidth(array): Grid system, column number is determined by device width, for example
5-column
  • gridWidth: [0,400,600,800,1200]
device_width column number
0~400 1
400~600 2
600~800 3
800~1200 4
>1200 5
2-column
  • gridWidth: [0,400]
device_width column number
0~400 1
>400 2
1-column
  • gridWidth: [0]
device_width column number
>0 1
  • refresh(int): period of screen detection in millisecond
  • scrollbottom(object): some action setting as reached the end of scrollbar
    • ele(element): owner of scrollbar, which is the parent element of $('box') by default.
    • endtxt(string): reminding message as reached the end of scrollbar
    • gap(int): if the distance to the bottom is smaller than gap, then will execute callback function.
    • callback(funciton): user-defined action as reached the end of scrollbar

γ€€ γ€€

Stop,Restart Waterfall effect

Waterfall will continuingly detect your screen action. Therefore, if you want to stop its detection, method is showed as below.

$(function(){
	// Launch waterfall 
	$('box').waterfall();

	// Stop it
	$('box').waterfall('stop');
	
	// Restart it
	$('box').waterfall();	
})

Waterfall will distinguish the target by the container of $('box'). Therefore, stop action will only be activated to your specific container when there are two or more Waterfall container on Web. γ€€ γ€€

Auto load more data on page scroll

As scrollbottom is used, it's very likely that you would load some new content to $('box'). Then, sort allows you to rearrange every elements in container. Also, $('box')(container itself) will be transfered to callback function for you to manipulate.

var setting = {
	scrollbottom : {
		callback: funciton(container){
			// if scroll to bottom, load more data...
			$.ajax({}).done(function(data){

				// resort elements
				container.waterfall('sort');

			});
		}
	}
};
$(function(){
	$('box').waterfall(setting);
})

If there is nothing more to be loaded in the container, then it means reaching the end of scrollbar. At this moment, you should remind user that there is "no more data", and you can create your own reminding message by setting endtxt.

var setting = {
	scrollbottom : {
		endtxt : 'No More Data !!',
		callback: funciton(container){
			// if scroll to bottom, load more data...
			$.ajax({}).done(function(data){
				if(data)	
					// resort elements
					container.waterfall('sort');
				else
					// done, show message
					container.waterfall('end');
			});
		}
	}
};

$(function(){
	$('box').waterfall(setting);
})

❗ Notice that if you execute $('box').waterfall("stop"), then scrollbottom and $('box').waterfall("sort") will be disabled.

Besides, container.waterfall('end') will not stop the detection but executing $('box').waterfall("stop") is the only way.

γ€€ γ€€

Overwrite setting

Waterfall setting accepts overwriten by importing the setting object. And nothing but the specific target will be updated by the transfered setting data.

var setting = {
	gap: 10,
	gridWidth: [0,400,600,800,1200],
	refresh: 500,
};

$(function(){
	$('box').waterfall(setting);

	// only update "gap" value
	$('box').waterfall( {gap:30} );
})

γ€€ γ€€

License

Waterfall is Apache License You can find it in the root directory of this source tree.

More...

If any suggestion, use issue! I will be glad to discuss with you.
Also, I welcome more contributers and hope to make this Plug-in even better(Pull-requests).

jquery.waterfall's People

Contributors

carr1005 avatar chungchi300 avatar gitter-badger avatar linzap avatar martin81930 avatar scandal0705 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.