How to handle scrolling with jQuery. Today we continue jQuery reviews, and our article will about event handling of scrollbar. Possible you saw such feature as ajaxy loading of new information when we scroll to end of page. As example here: http://www.dzone.com/links/index.html, or in your facebook page and other websites. Interesting feature isn’t it? Or, also will possible to stick some elements when our scroll moving out necessary positions. Or, we can handle events when scroller reach defined element at our page (and, as example – load some extra content on this event). Today I will show you how to do this.
We will use new jQuery plugin – Waypoints. This small jQuery plugin allow us to perform different actions whenever we using scroller. As example – scrollint to some defined element. Firstly – lets check our prepared demo
Ok, download the example files and lets start coding !
好的,下载示例文件并开始编码!
步骤1. HTML (Step 1. HTML)
As usual, we start with the HTML.
和往常一样,我们从HTML开始。
This is our main page code.
这是我们的主页代码。
index.html (index.html)
Post number 1
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
Post number 2
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
Post number 3
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
Post number 4
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
Post number 5
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
Post number 1
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
Post number 2
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
Post number 3
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
Post number 4
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
Post number 5
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears. A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
Make attention that here we draw our navigation menu, five posts and in footer we prepared 2 elements: link to next page: other.php?step=1 and another element which will allow us to jump to top of page. By default that element will invisible (CSS).
Here are all used JS files. This is of course jQuery library itself + our new plugin:
这是所有使用过的JS文件。 这当然是jQuery库本身+我们的新插件:
js / jquery-1.4.4.min.js和js / waypoints.min.js (js/jquery-1.4.4.min.js and js/waypoints.min.js)
js / main.js (js/main.js)
$(document).ready(function() {
// Blink fast when we reached this element (post number 4)
$('#post4').waypoint(function() {
$(this).fadeOut(300).fadeIn(300);
}, {
offset: '50%', // middle of the page
triggerOnce: true
});
// ajaxy content
var $loading = $("
$(document).ready(function() {
// Blink fast when we reached this element (post number 4)
$('#post4').waypoint(function() {
$(this).fadeOut(300).fadeIn(300);
}, {
offset: '50%', // middle of the page
triggerOnce: true
});
// ajaxy content
var $loading = $("
This is most interesting and important part of our project. Firstly I should to show you format of initialization of waypoints plugin. By default this is:
这是我们项目中最有趣,最重要的部分。 首先,我将向您展示路标插件的初始化格式。 默认情况下是:
$('some_element').waypoint([handler], [options]);
$('some_element').waypoint([handler], [options]);
Both params – optional, here are from documentation:
这两个参数–可选,来自文档:
handler — function, optional param, – callback function called when the user scrolls past the element. The function signature is function(event, direction), where ‘event’ is a usual jQuery event object and ‘direction’ is a string, either ‘down’ or ‘up’ indicating which direction the user is scrolling.
Now lets look to our most easy sample – where we will blink post (once) when the we scrolls to this element (at middle of page):
现在,让我们看一下最简单的示例–当我们滚动到该元素(在页面中间)时,我们将在此处闪烁一次(一次):
$('#post4').waypoint(function() {
$(this).fadeOut(300).fadeIn(300);
}, {
offset: '50%', // middle of the page
triggerOnce: true
});
$('#post4').waypoint(function() {
$(this).fadeOut(300).fadeIn(300);
}, {
offset: '50%', // middle of the page
triggerOnce: true
});
So, I created waypoint to element ‘#post4’, and handling event – scrolling to this element when it located at middle of page. This post should blink once (triggerOnce = true).
As you can see, firstly I defined new loading element, options for waypoint. And, when we reached the bottom of the page I removing current waypoint, draw loading element, loading via $.get new content from my other.php, adding new posts, removing loading element, updating link to More, and, re-create waypoint again (for new positions). So, now its time to check our other.php file
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
EOF;
$aPosts[] = <<
Post number 7 (loaded ajaxy)
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
EOF;
$aPosts[] = <<
Post number 8 (loaded ajaxy)
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
EOF;
$aPosts[] = <<
Post number 9 (loaded ajaxy)
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
EOF;
$aPosts[] = <<
Post number 7 (loaded ajaxy)
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
EOF;
$aPosts[] = <<
Post number 8 (loaded ajaxy)
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
EOF;
$aPosts[] = <<
Post number 9 (loaded ajaxy)
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.
In begining – I defined array of all posts (sure that in your project anything will in database). After, depends on accepted param ‘step’ we will draw necessary result, plus – link new updated link to another results (other.php?step=2, other.php?step=3 etc)
Here are continue of documentation. Functions and options of waypoint:
这是文档的继续。 航点的功能和选项:
$(‘some_element’).waypoint(‘destroy’) – this function will fully unregister current waypoint, unbind all waypoint event handlers. $('some_element')。waypoint('destroy')–此函数将完全注销当前的航路点,并取消绑定所有航路点事件处理程序。
$(‘some_element’).waypoint(‘remove’) – this function will unregisters the elements as waypoints and wipes any custom options, but leaves the ‘waypoint.reached’ events bound. Calling ‘$(‘some_element’).waypoint’ again in the future would re-register the waypoint and the old handlers would continue to work. $('some_element')。waypoint('remove')–此函数将取消注册元素为航点并擦除所有自定义选项,但将'waypoint.reached'事件绑定。 将来再次调用“ $('some_element')。waypoint”将重新注册该航点,而旧的处理程序将继续工作。
$(‘some_element’).waypoint.defaults – default options of object that is extended when calling ‘.waypoint’. It have next properties:
offset — number | string | function (default: 0), – tell us how far the top of the element must be from the top of the browser window to trigger waypoint. It can be a number, which is taken as a number of pixels, a string representing a percentage of the viewport height, or a function that will return a number of pixels. Example – offset: ‘100%’
$.waypoints(‘refresh’) – that function will perform recalculation of all waypoint`s trigger point based on its offset value. By default this called automatically (whenever the window is resized, new waypoints are added, or a waypoint’s options are modified). If your project is changing the DOM structure or page layout without doing one of these things, you may want to manually call this refresh. $ .waypoints('refresh')–该函数将基于其偏移值重新计算所有航点的触发点。 默认情况下,这会自动调用(无论何时调整窗口大小,添加新的航路点或修改航路点的选项)。 如果您的项目在不执行以下任何一项操作的情况下更改了DOM结构或页面布局,则可能需要手动调用此刷新。
$.waypoints(‘viewportHeight’) – that function will return the height of the viewport, adjusting for inconsistencies that come with calling ‘$(window).height()’ in iOS. Recommended for use within any offset functions. $ .waypoints('viewportHeight')–该函数将返回视口的高度,并针对在iOS中调用'$(window).height()'引起的不一致进行调整。 建议在任何偏移功能中使用。
$.waypoints.settings – settings, which determine some of the plugin`s behavior:
$ .waypoints.settings –设置,用于确定插件的某些行为:
boolean (default: true), – determines which waypoints to trigger events for if a single scroll change passes more than one waypoint. If false, only the last waypoint is triggered and the rest are ignored. If true, all waypoints between the previous scroll position and the new one are triggered in order.布尔值(默认值:true) ,-确定如果单个滚动更改通过了多个航路点,则触发事件的航路点。 如果为false,则仅触发最后一个航路点,其余的将被忽略。 如果为true,则会依次触发上一个滚动位置和新滚动位置之间的所有路标。
number (default: 200), – the refresh performed during window resizes is throttled. This value is the rate-limit in milliseconds between resize refreshes.数字(默认值:200) ,–限制窗口调整大小期间执行的刷新。 此值是两次大小调整刷新之间的速率限制(以毫秒为单位)。
number (default: 100), – checking for any crossed waypoints during the window scroll event is throttled. This value is the rate-limit in milliseconds between scroll checks. (You can notice that we already using ‘scrollThrottle’ in our sample)数字(默认值:100) ,–在限制窗口滚动事件期间检查是否有任何交叉的航路点。 此值是两次滚动检查之间的速率限制(以毫秒为单位)。 (您会注意到,我们已经在示例中使用了“ scrollThrottle”)
现场演示
结论 (Conclusion)
Today we review new interesting jQuery plugin which can enhance user interface of your website. If is you were wondering – do not forget to thank. I would be grateful for your interesting comments. Good luck!
这里写点抛砖引玉,希望大家能把自己整理的问题及解决方法晾出来,Mark一下,利人利己。
出现问题先搜一下文档上有没有,再看看度娘有没有,再看看论坛有没有。有报错要看日志。下面简单罗列下常见的问题,大多文档上都有提到的。
1、repeated column width is largerthan paper width:
这个看这段话应该是很好理解的。比如做的模板页面宽度只能放
这个问题我实在是为整个 springsource 的员工蒙羞
如果大家使用 spring 控制事务,使用 Open Session In View 模式,
com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.
简单模拟实现数据库连接池
实例1:
package com.bijian.thread;
public class DB {
//private static final int MAX_COUNT = 10;
private static final DB instance = new DB();
private int count = 0;
private i
using System;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace WindowsFormsApplication1
{
Configuring Spring and JTA without full Java EE
http://spring.io/blog/2011/08/15/configuring-spring-and-jta-without-full-java-ee/
Spring doc -Transaction Management
http://docs.spring.io/spri