jQuery回到顶部

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Back to Top</title>
<link rel="stylesheet" href="">
<style>
#content {
height: 2000px;
}
#back-to-top.show {
opacity: 1;
}
#back-to-top {
position: fixed;
bottom: 40px;
right: 40px;
z-index: 9999;
width: 32px;
height: 32px;
text-align: center;
line-height: 30px;
background: #f5f5f5;
color: #444;
cursor: pointer;
border-radius: 2px;
text-decoration: none;
opacity: 0;
transition: opacity .2s ease-out;
border: 1px solid #ddd;
}
</style>
</head>
<body>
<div id="content">Scroll &darr;</div>
<a href="#" id="back-to-top" title="Back to top">&uarr;</a> <script src="jquery-1.9.0.min.js"></script>
<script>
if ($('#back-to-top').length) {
var scrollTrigger = 100; // px // $(window).scrollTop()与 $(document).scrollTop()产生结果一样
// 一般使用document注册事件,window使用情况如 scroll, scrollTop, resize
$(window).on('scroll', function () {
if ($(window).scrollTop() > scrollTrigger) {
$('#back-to-top').addClass('show');
} else {
$('#back-to-top').removeClass('show');
}
}); $('#back-to-top').on('click', function (e) {
// html,body 都写是为了兼容浏览器
$('html,body').animate({
scrollTop: 0
}, 700); return false;
});
}
</script>
</body>
</html>

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

  1. Jquery 回到顶部

    转:http://www.cnblogs.com/DemoLee/archive/2012/04/20/2459082.html 用jQuery实现渐隐渐显的返回顶部效果(附多图)   先来看几个图片 ...

  2. jQuery回到顶部插件jQuery GoUp

    插件描写叙述 jQuery GoUp!是一个简单的jQuery插件,让你的网页用户直接回到顶部. 用法很easy 引用jquery库和jquery.goup.min.js到你的页面 <scrip ...

  3. html css jquery 回到顶部按钮

    今天做了个回到顶部的功能,在这里记录一下,有需要可以拿去试试! CSS部分,很简单就一个class /*回到顶部*/ .back-top { position: fixed; right: 15px; ...

  4. Jquery回到顶部插件【query.scrollUp.js】使用

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta na ...

  5. jquery 回到 顶部

    1. 页面内容较多, 从底部超链接 点击回到页面顶部 // 回到顶部 var $top = $('<a class="doc-gotop" href="javasc ...

  6. Jquery回到顶部功能

    问题描述: 在网页中,我们经常会由于网页内容过长,而需要在浏览网页时有一个快速回到网页顶部的功能,在浏览网页内容离顶部有一段距离时,出现快速回到网页顶部的工具,从而能使我们的网页更人性化. 问题的产生 ...

  7. jquery 回到顶部,简洁大方

    效果

  8. JQuery 回到顶部效果

    图片,CSS/HTML/JS代码都在,可以直接用了. CSS代码 <style type="text/css"> #gs_feedback_gotop { _displ ...

  9. Jquery回到顶部效果

    <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> &l ...

随机推荐

  1. 文件操作1-php

    is_file (PHP 3, PHP 4, PHP 5) is_file -- 判断给定文件名是否为一个正常的文件 说明 bool is_file ( string filename ) 如果文件存 ...

  2. oracle之分组内的字符串连接

    实现效果: 例如下面的数据[php] groupid        personid        name 1          a          超级管理员2          b       ...

  3. js中的模块化编写思维

    作为一个新手程序员,在编程时一定要刻意锻炼自己的模块化编写思路,但是究竟什么才是模块化编写对于新人来说还是不太能够直观的理解,下面就举个简单的例子来说明一下 概念:最早接触模块化的说法是从java上, ...

  4. 解决SQL Server Management Studio Express不支持更新全文目录的方法

    微软的说法:https://msdn.microsoft.com/zh-cn/library/ms365247.aspx 可以用命令创建: A.创建唯一索引.全文目录和全文索引 以下示例对 Adven ...

  5. 在jQuery.getData中renderCallback使用不同创建方式的结果

    JavaScript 中需要创建函数的话,有两种方法:函数声明.函数表达式,各自写法如下:// 方法一:函数声明function foo() {}// 方法二:函数表达式var foo = funct ...

  6. js监控键盘大小写事件

    JavaScript键盘事件侦听    在使用JavaScript做WEB键盘事件侦听捕获时,主要采用onkeypress.onkeydown.onkeyup三个事件进行出来.该三个事 件的执行顺序如 ...

  7. 实验一:基于Winsock完成简单的网络程序开发

    第一部分:简答的UDP网络通信程序 // UDP5555.cpp : Defines the entry point for the application. //================== ...

  8. 洛谷 P1331 海战

    传送门 题解:由于船是方形的,所以比较简单.但是考试的时候跪了,orz.忘了考虑类似一圈井号中间有一摊水.          可以只考虑这个点上方和左边点的情况,这样分为四种情况.一种是左边是一滩水, ...

  9. poj2352 Stars

    http://poj.org/problem?id=2352 #include <cstdio> #include <cstring> #define maxn 400000 ...

  10. activitie5 流程入门例子

    流程这个东西在ERP项目用得比较多.在网上找到一个例子,与大家分享一下.http://yiyiboy2010.iteye.com/blog/1530924 感谢原博主提供 http://blog.ch ...