mootools_使用MooTools ScrollSpy滚动“同意条款”组件

mootools

Remember the good old days of Windows applications forcing you to scroll down to the bottom of the "terms and conditions" pane, theoretically in an effort ensure that you actually read them? You're saying "No David, don't do it." Too late -- I've done it.

还记得Windows应用程序的美好时光,它迫使您向下滚动到“条款和条件”窗格的底部,从理论上确保您确实阅读了它们吗? 您说的是“不,大卫,不要这样做。” 为时已晚-我已经做到了。

HTML (The HTML)


<form method="post">
	<div id="terms-pane">
		<h2>Terms & Conditions</h2>
		<p>Pellentesque habitant morbi tristique senectus...</p>
		<p>Pellentesque habitant morbi tristique senectus...</p>
		<!-- many more... -->
	</div>
	<input type="submit" name="submit" id="submit" value="Submit" />
</form>


The scrolling area must be wrapped with a DIV.

滚动区域必须用DIV包裹。

CSS (The CSS)


	#terms-pane	{ width:800px; height:200px; overflow:scroll; border:1px solid #ccc; background:#eee; margin:5px 0; padding:10px 20px; }


The aforementioned DIV should have an explicit height and the overflow set to scroll.

前面提到的DIV应该有一个明确的高度,并且溢出应设置为滚动。

MooTools JavaScript (The MooTools JavaScript)


window.addEvent('domready',function() {
	//disable submit
	var submit = $('submit');
	submit.disabled = true;
	//scrollspy
	var div = $('terms-pane'), height = div.getScrollSize().y;
	var spy = new ScrollSpy({
		container: div,
		min: div.getScrollSize().y - div.getSize().y, //tolerance
		onEnter: function() {
			submit.disabled = false;
		}
	});
});


We start out by disabling the submit button. Then we calculate both the height and the scroll height of the DIV, subtracting one from the other to get the allowance range of the scrolling area. When the user scrolls down there, ScrollSpy fires the enter event and we know the user has hit the bottom!

我们首先禁用提交按钮。 然后,我们计算DIV的高度和滚动高度,将它们彼此相减,得到滚动区域的允许范围。 当用户向下滚动时,ScrollSpy触发enter事件,我们知道用户已经触底!

I used to hate these things when they were included in Windows application installs. If you want this type of effect though, here it is.

当它们包含在Windows应用程序安装中时,我曾经讨厌这些东西。 如果您想要这种效果,就在这里。

翻译自: https://davidwalsh.name/scrollspy-terms

mootools

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值