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. centos账户的uid和gid

    修改/etc/passwd和/etc/group文件的UID和GID为0,可以获得root权限,不过不推荐~ UID和GID Linux系统如何区别不同的用户呢?可以很自然地想到,使用不同的用户名应该 ...

  2. Phalcon 的 bootstrap.php 自动加载完成;非常人性化的设计

    <?php /** * Bootstraps the application */ use Phalcon\DI\FactoryDefault as PhDi, Phalcon\Config a ...

  3. WEB兼容性之JS

    1. 获取iframe的window对象 //三种方法 window.iframeName window.frames[iframeName] document.getElementById(ifra ...

  4. elasticsearch常用的插件

    deb 安装/usr/share/elasticsearch/   https://github.com/hangxin1940/elasticsearch-cn-out-of-box 包可以参考   ...

  5. codevs 1153 道路游戏

    传送门   题目描述 Description 小新正在玩一个简单的电脑游戏.游戏中有一条环形马路,马路上有n 个机器人工厂,两个相邻机器人工厂之间由一小段马路连接.小新以某个机器人工厂为起点,按顺时针 ...

  6. 谈谈依赖注入DI

    控制反转(Inversion of Control,英文缩写为IoC)是一个重要的面向对象编程的法则来削减计算机程序的耦合问题,也是轻量级的Spring框架的核心. 控制反转一般分为两种类型,依赖注入 ...

  7. 转:ElasticSearch 插件安装

    原文来自于:http://www.07net01.com/linux/Elasticsearch_chajiananzhuang_21257_1350993328.html 进入elasticsear ...

  8. Node.js 安装 初体验(1)

    1.安装nodejs http://nodejs.org/download/  自动根据系统下载自己的版本node.js 2.环境变量 windows 安装,不需要配置环境变量   mac安装后,会提 ...

  9. gnome/KDE安装,gnome出现问题,重新安装nvdia驱动

    重新安装显示gtx745驱动NVIDIA-Linux-x86_64-346.59.run, yum groupremove kde-desktop yum groupinstall "Des ...

  10. js类型判断及鸭式辨型

    目录 instanceof constructor 构造函数名字 鸭式辨型 三种检测对象的类方式: instanceof.constructor .构造函数名字 用法如下: 1)instanceof ...