<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
body{
width: 100%;
height: 10000px;
}
#totop{
width: 50px;
height: 50px;
line-height: 50px;
background: magenta;
font-size: 20px;
position: fixed;
right: 50px;
bottom: 50px;
}
</style>
</head>
<body>
</body>
<script src="js/jquery/jquery-1.8.3.min.js" ></script>
<script> //写在common.js文件中用来调用即可
//1获取滚动条当前的位置
function getScrollTop() {
var scrollTop = 0;
if (document.documentElement && document.documentElement.scrollTop) {
scrollTop = document.documentElement.scrollTop;
} else if (document.body) {
scrollTop = document.body.scrollTop;
}
return scrollTop;
}; //2获取文档完整的高度
function getScrollHeight() {
return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}; //3回到顶部
function toTop(n) {
$(window).on('scroll', function() {
//console.log(getScrollTop()+"!"+getScrollHeight());
if ($("#totop").size() > 0) {
if (getScrollTop() < $(window).height() * n) {
$("#totop").remove();
}
} else {
if (getScrollTop() >= $(window).height() * n) {
$("body").after("<div id='totop'>totop</div>");
//插入了新标签 ,记得添加样式!
$("#totop").on('click', function() {
scroll(0,200);
});
}
}
});
}; //xxx.js文件来执行
$(function(){
toTop(2);
})
</script>
</html>

回到顶部totop的更多相关文章

  1. animate平滑回到顶部

    Js: //回到顶部 $(".totop").click(function () { $("body,html").animate({scrollTop: 0} ...

  2. jQuery写toTop(回到顶部)效果

    在通常的网站开发中,页面有时候会很长,尤其是一些电商网站,为了提高用户的体验效果,我们通常会增加一个回到顶部的按钮,这个按钮我们同城会使用fixed定位,将其定位在当前可视区域某一固定位置.这个效果用 ...

  3. JS原生回到顶部效果

    // 回到顶部 onload = function () { var oBtnTop = document.getElementById('toTop'); var timer = null; oBt ...

  4. octopress添加回到顶部按钮

    准备回到顶部的png图片一枚,可以随自己喜好google.分享我的 取名top.png,保存在octopress/source/images/top.png octopress/source/_inc ...

  5. Angular回到顶部按钮指令

    之前的分页代码指令化在线下测试没有问题,到服务器上就不运行了,所以那个先放一放. 今天来把"回到顶部"按钮指令化.首先是页面html: <!--回弹按钮--> < ...

  6. vue回到顶部组件

    html <template> <a href="javascript:;" class="toTop" @click="backT ...

  7. vue中回到顶部

    1. 回到顶部,使用 scrollIntoView 方法: Element.scrollIntoView方法滚动当前元素,进入浏览器的可见区域 该方法可以接受一个布尔值作为参数.如果为true,表示元 ...

  8. HTML元素跟随鼠标一起移动,网页中回到顶部按钮的实现

    对象跟随鼠标: 1.对象css设置绝对定位position: absolute; 2.获取鼠标坐标: 3.通过鼠标坐标计算出对象坐标位置,并设置为css定位的位置: document.onmousem ...

  9. 从微信小程序到鸿蒙js开发【13】——list加载更多&回到顶部

    鸿蒙入门指南,小白速来!从萌新到高手,怎样快速掌握鸿蒙开发?[课程入口] 目录: 1.list加载更多 2.list回到顶部 3.<从微信小程序到鸿蒙js开发>系列文章合集 1.list加 ...

随机推荐

  1. Codeforces Round #364 (Div. 2) C 二分处理+求区间不同字符的个数 尺取法

    C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. svn提示出错异常为remains in conflict

    查看原文:http://www.ibloger.net/article/225.html 提交冲突代码 commit -m "" E:/Program Files/MyEclips ...

  3. BZOJ 4766: 文艺计算姬

    4766: 文艺计算姬 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 456  Solved: 239[Submit][Status][Discuss] ...

  4. Docker(六):容器

    一.启动容器 启动容器有两种方式,一种是基于镜像新建一个容器并启动,另一个是将一个在终止状态的容器重新启动,因为Docker的容器实在是太轻量了,很多用户都可以随时删除和新创建容器. 新建并启动 $s ...

  5. C语言中的内存相关问题

    内存是用来存储数据与程序的,对我们写程序来说非常重要.所以内存对程序来说几乎是本质需求.越简单的程序需要越少的内存,而越庞大越复杂的程序需要更多的内存. 注意:在嵌入式系统中有ROM和RAM两类内存, ...

  6. hdu 2582(数论相关定理+素数筛选+整数分解)

    f(n) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  7. Codeforces 899 C.Dividing the numbers-规律

      C. Dividing the numbers   time limit per test 1 second memory limit per test 256 megabytes input s ...

  8. FZU 1075 分解素因子【数论/唯一分解定理/分解素因子裸模板】

    [唯一分解定理]:https://www.cnblogs.com/mjtcn/p/6743624.html 假设x是一个正整数,它的值不超过65535(即1<x<=65535),请编写一个 ...

  9. Codeforces 912E Prime Gift(预处理 + 双指针 + 二分答案)

    题目链接 Prime Gift 题意  给定一个素数集合,求第k小的数,满足这个数的所有质因子集合为给定的集合的子集. 保证答案不超过$10^{18}$ 考虑二分答案. 根据折半的思想,首先我们把这个 ...

  10. 10.1综合强化刷题 Day3 morning

    竞赛时间:????年??月??日??:??-??:?? 题目名称 a b c 名称 a b c 输入 a.in b.in c.in 输出 a.out b.out c.out 每个测试点时限 1s 1s ...