mootools_使用MooTools的“顶级”水印

mootools

Whenever you have a long page worth of content, you generally want to add a "top" anchor link at the bottom of the page so that your user doesn't have to scroll forever to get to the top. The only problem with this method is that I may want to get to the top of the page from somewhere in the middle. Using MooTools, we can create a "top" link as a watermark that follows the users down the page.

每当您的页面内容很长时,通常都希望在页面底部添加一个“顶部”锚链接,以便您的用户不必永远滚动即可到达顶部。 这种方法的唯一问题是,我可能想从中间某个地方到达页面顶部。 使用MooTools,我们可以创建“顶部”链接作为水印,使用户跟随页面。

XHTML (The XHTML)


<a href="#top" id="gototop" class="no-click no-print">Top of Page</a>


Place this anywhere inside the page that you would like.

将此放置在您想要的页面内的任何位置。

CSS (The CSS)


#gototop { display:none; position:fixed; right:5px; bottom:5px; }


This code positions the element in a fixed position so it always stays in the same spot.

此代码将元素定位在固定位置,因此它始终位于同一位置。

MooTools JavaScript (The MooTools JavaScript)



/* smoothscroll - scroll smoothly to the top*/
new SmoothScroll({duration:500});

/* go to top after 300 pixels down */
var gototop = $('gototop');
gototop.set('opacity','0').setStyle('display','block');
window.addEvent('scroll',function(e) {
	gototop.fade((window.getScroll().y > 300) ? 'in' : 'out')
});


The code is surprisingly short. Of course we use SmoothScroll to make the transition smoothe. You may adjust the pixel trigger amount however you'd like. Unfortunately the above code doesn't work in IE6.

代码很短。 当然,我们使用SmoothScroll使过渡平滑。 您可以根据需要调整像素触发量。 不幸的是,以上代码在IE6中不起作用。

IE修复 (The IE Fix)


/* go to top */
var gototop = $('gototop');
gototop.set('opacity','0').setStyle('display','block');
window.addEvent('scroll',function(e) {
	if(Browser.Engine.trident4) {
		gototop.setStyles({
			'position': 'absolute',
			'bottom': window.getPosition().y + 10,
			'width': 100
		});
	}
	gototop.fade((window.getScroll().y > 300) ? 'in' : 'out')
});


I like this method so much that I use it on my website.

我非常喜欢这种方法,因此可以在我的网站上使用它。

Shouldn't this be a plugin?
这不应该是插件吗?

Don't worry -- ScrollSpy is coming soon enough. :)

别担心-ScrollSpy即将推出。 :)

翻译自: https://davidwalsh.name/mootools-watermark

mootools

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值