关于top按钮的网页设置
方法一:
直接用html实现,没有缓冲的效果,直接彪到顶部。
HTMl: <a id="return-top" href="#top">
<span class="pointer"></span>
<p class="black-circle">TOP</p>
</a> CSS: #return-top{
width:51px;
height:51px;
position:fixed;
right:0;
bottom:0;
z-index: 100;
border-radius: 51px;
background: #424243; }
.pointer{
display: inline-block;
background: url(../img/icon_backtotop.png) no-repeat top center;
width:21px;
height:13px;
position: relative;
top:16px;
left:15px;
}
.black-circle{ color:#fff;
text-align: center;
width:51px;
font-size: 12px;
height:12px;
margin-top:15px;
}
#return-top:hover .pointer{
top:10px;
}
方法二:在方法一的基础之上加缓冲效果,即添加js实现
js代码如下:
/**
* 作者:我是UED ,http://www.iamued.com/qianduan/816.html
* 回到页面顶部
* @param acceleration 加速度
* @param time 时间间隔 (毫秒)
**/
function goTop(acceleration, time) {
acceleration = acceleration || 0.1;
time = time || 16; var x1 = 0;
var y1 = 0;
var x2 = 0;
var y2 = 0;
var x3 = 0;
var y3 = 0; if (document.documentElement) {
x1 = document.documentElement.scrollLeft || 0;
y1 = document.documentElement.scrollTop || 0;
}
if (document.body) {
x2 = document.body.scrollLeft || 0;
y2 = document.body.scrollTop || 0;
}
var x3 = window.scrollX || 0;
var y3 = window.scrollY || 0; // 滚动条到页面顶部的水平距离
var x = Math.max(x1, Math.max(x2, x3));
// 滚动条到页面顶部的垂直距离
var y = Math.max(y1, Math.max(y2, y3)); // 滚动距离 = 目前距离 / 速度, 因为距离原来越小, 速度是大于 1 的数, 所以滚动距离会越来越小
var speed = 1 + acceleration;
window.scrollTo(Math.floor(x / speed), Math.floor(y / speed)); // 如果距离不为零, 继续调用迭代本函数
if(x > 0 || y > 0) {
var invokeFunction = goTop( +acceleration+ , +time+ );
window.setTimeout(invokeFunction, time);
}
}
方法三:‘TOP’默认是隐藏的,只要滚动条,滚动到一定高度时就显示,否则就隐藏。
这样我可能想从中间某处回到页面的顶部成为可能。
The HTML :
<a href=#top id=gototop >Top of Page</a>
The CSS :
#gototop { display:none; position:fixed; right:5px; bottom:5px; color:green; font-weight:bold; text-decoration:none; border:1px solid green; background:Lightgreen; padding:10px; } #gototop { text-decoration:underline; }
The MooTools JavaScript : 注意: 我们需要MooTools Core 库的同时,也需要MooTools More 库中的 Fx.Scroll.js 和 Fx.SmoothScroll.js 两大文件。
window.addEvent('domready',function() {
new SmoothScroll({duration:700});
/* go to top */
var go = $('gototop');
go.set('opacity','0').setStyle('display','block');
window.addEvent('scroll',function(e) {
if(Browser.Engine.trident4) {
go.setStyles({
'position': 'absolute',
'bottom': window.getPosition().y + 10,
'width': 100
});
}
go.fade((window.getScroll().y > 300) ? 'in' : 'out')
});
});
方法3:还有一个例子是动态生成‘TOP’。
The MooTools JavaScript :
/**
* back-to-top: unobtrusive global 'back to top' link using mootools 1.2.x
* This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
* http://creativecommons.org/licenses/by-sa/3.0/
*/ // hide the effect from IE6, better not having it at all than being choppy.
if (!Browser.Engine.trident4) {
// element added onload for IE to avoid the operation aborted bug. not yet verified for IE8 as it's still on beta as of this modification.
window.addEvent((Browser.Engine.trident ? 'load' : 'domready'), function(){
var target_opacity = 0.64;
new Element('span', {
'id': 'back-to-top',
'styles': {
opacity: target_opacity,
display: 'none',
position: 'fixed',
bottom: 0,
right: 0,
cursor: 'pointer'
},
'text': 'back to top',
'tween': {
duration: 200,
onComplete: function(el) { if (el.get('opacity') == 0) el.setStyle('display', 'none')}
},
'events': {'click': function() {
/*location是javascript里边管理地址栏的内置对象,比如location.href就管理页面的url,用 location.href=url就可以直接将页面重定向url。而location.hash则可以用来获取或设置页面的标签值。比如 http://ued.alimama.com#admin的location.hash=#admin,利用这个属性值可以实现很多效果。*/
if (window.location.hash) { window.location.hash = '#top'; }
else { window.scrollTo(0, 0);/*把窗口内容滚动到指定的坐标。*/ }
}}
}).inject(document.body); window.addEvent('scroll', function() {
var visible = window.getScroll().y > (window.getSize().y * 0.8);
if (visible == arguments.callee.prototype.last_state) return; // fade if supported
if (Fx && Fx.Tween) {
if (visible) $('back-to-top').fade('hide').setStyle('display', 'inline').fade(target_opacity);
else $('back-to-top').fade('out');
} else {
$('back-to-top').setStyle('display', (visible ? 'inline' : 'none'));
} arguments.callee.prototype.last_state = visible
});
});
}
The jQuery JavaScript :
需要jQuery’s ScrollTo plugin 插件添加一些平滑的锚。
//plugin
jQuery.fn.topLink = function(settings) {
settings = jQuery.extend({
min: 1,
fadeSpeed: 200
}, settings);
return this.each(function() {
//listen for scroll
var el = $(this);
el.hide(); //in case the user forgot
$(window).scroll(function() {
if($(window).scrollTop() >= settings.min)
{
el.fadeIn(settings.fadeSpeed);
}
else
{
el.fadeOut(settings.fadeSpeed);
}
});
});
}; //usage w/ smoothscroll
$(document).ready(function() {
//set the link
$('#gototop').topLink({
min: 400,
fadeSpeed: 500
});
//smoothscroll
$('#gototop').click(function(e) {
e.preventDefault();
$.scrollTo(0,300);
});
});
以上代码针对ie7不使用,针对ie7代码如下:
//plugin
jQuery.fn.topLink = function(settings) {
settings = jQuery.extend({
min: 1, fadeSpeed: 200,
ieOffset: 50
}, settings);
return this.each(function() {
//listen for scroll
var el = $(this);
el.css('display','none'); //in case the user forgot
$(window).scroll(function() {
//stupid IE hack
if(!jQuery.support.hrefNormalized) {
el.css({
'position': 'absolute',
'top': $(window).scrollTop() + $(window).height() - settings.ieOffset
});
}
if($(window).scrollTop() >= settings.min)
{
el.fadeIn(settings.fadeSpeed);
}
else
{
el.fadeOut(settings.fadeSpeed);
}
});
});
}; $(document).ready(function() {
$('#gototop').topLink({
min: 400,
fadeSpeed: 500
});
//smoothscroll
$('#gototop').click(function(e) {
e.preventDefault();
$.scrollTo(0,300);
});
});
文章转载地址为:http://www.missyuan.com/viewthread.php?tid=450821
关于top按钮的网页设置的更多相关文章
- JavaScript自动生成博文目录导航/TOP按钮
博客园页面添加返回顶部TOP按钮 进入网页管理->设置 在"页面定制CSS代码"中添加如下css样式,当然你可以改为自己喜欢的样式 此处可以将背景色background-co ...
- TOP按钮
TOP按钮 博客园页面添加返回顶部TOP按钮 进入网页管理->设置 在"页面定制CSS代码"中添加如下css样式,当然你可以改为自己喜欢的样式 此处可以将背景色backgro ...
- jQuery制作go to top按钮
转自:http://www.w3cplus.com/jquery/scrolling-to-the-top-with-jquery 每每看到网友Blog的页面底部或中间有一个按钮回到页面顶部,羡慕死人 ...
- MFC 使用位图按钮,并且设置按钮的鼠标悬停效果
系统环境:Windows 10软件环境:Visual C++ 2013 SP1本次目的:使用位图按钮,并且设置按钮的鼠标悬停效果 在用MFC开发时,界面是比较不好开发的一块.VC中自带了CBitmap ...
- 将网页设置为允许 XMLHttpRequest 跨域访问
在非IE下,使用XMLHttpRequest 不能跨域访问, 除非要访问的网页设置为允许跨域访问. 将网页设置为允许跨域访问的方法如下: Java Response.AddHeader("A ...
- ios开发之--textview意见反馈页面(占位label,字数统计,提交按钮的交互设置)
记录一个页面的功能: textview的占位符,字数统计,提交按钮的交互设置,具体效果图如下:
- Qt中使用setStyleSheet对QPushButton按钮进行外观设置
Qt中使用setStyleSheet对按钮进行外观设置 字体颜色的设置一般时以下两种方案: (1)属于QWidget子类的一些控件 可以直接使用样式表,例如label->setStyleShee ...
- js实现用按钮控制网页滚动、以及固定导航栏效果
实现效果如下: 页面内有三个按钮,分别控制页面向上.向下移动,以及暂停,并设置有导航栏,在滚动到某一位置时显示.且当用户主动控制鼠标滑轮时,滚动效果自动关闭.本页面只是演示如何实现,进行了简单的布局, ...
- winfrom_动态添加按钮button(设置颜色,大小,按钮字体大小、颜色,位置,事件)
List<string> strColor = new List<string>(); strColor.Add("#e67817"); strColor. ...
随机推荐
- n2n搭建手记-2-V2
n2n-V2搭建 [1.]在V1中遇到的问题 在完成V1搭建后,边缘节点1台机器由centos 6.5 重装为Centos 7 ,再次重加入V1时遇到 与节点其他机器 可 ping通.能通过机器的公网 ...
- [CF986E]Prince's Problem
题意:给一棵带点权$w_i$的树,多次询问$(u,v,x)$,求出$\prod\limits_{i\in\text{path}(u,v)}(w_i,x)$ 因为是乘法,所以可以把路径询问拆成到根询问, ...
- 8.6(java学习笔记)类加载过程及类加载器
一.类加载 1.加载 将class字节码加载到内存中,同时在方法区形成改类运行时数据结构. 同时在堆中产生一个Class对象,反射就是获取这个对象并对其进行操作. 2.链接 2.1验证:验证加载的类信 ...
- 通读《STL源码剖析》之后的一点读书笔记
直接逼入正题. Standard Template Library简称STL.STL可分为容器(containers).迭代器(iterators).空间配置器(allocator).配接器(adap ...
- Problem R: 求斐波那契数列的前n项值
#include<stdio.h> int main() { int n; while(scanf("%d",&n)!=EOF){ int x1,x2,i,x; ...
- Scala实战高手****第13课:Scala模式匹配实战和Spark源码鉴赏
package com.dt.spark.scala.bascis class Dataframework case class Computerframework (name:String,popu ...
- 使用FluentValidation来进行数据有效性验证
之前我介绍过了使用系统自带的Data Annotations来进行数据有效性验证,今天在CodePlex上逛的时候,发现了一个非常简洁好用的库:FluentValidation 由于非常简洁,就直接拿 ...
- 继续推荐几款VisualStudio的插件(二)
今天晚上闲着的时候逛了一下,发现了几款不错的VisualStudio插件,这里推荐一下: Exception Breaker 在调试的时候,为了及时发现错误,我们常常会打开"总是引发所有CL ...
- BigDecimal类整除报错的解决方案
例如: BigDecimal num1 = new BigDecimal("10"); BigDecimal num2 = new BigDecimal("3" ...
- vulkan
https://gfxbench.com/device.jsp?benchmark=gfx40&os=Android&api=gl&D=Asus+ZenFone+4+%28Ad ...