jQuery中animate与scrollTop、offset().top实例
<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>scrollTop与offset.top、animate</title>
<style>
* {
margin: 0;
padding: 0
} body {
margin: 0 auto;
max-width: 640px;
background-color: #fbfbfb;
padding: 10px;
} .bd {
height: 1650px;
overflow: hidden;
} .btn_animate {
position: absolute;
width: 120px;
height: 30px;
line-height: 30px;
background-color: rgb(129, 26, 26);
color: #fff;
text-align: center;
} .btn_ho {
position: absolute;
top: 40px;
left: 0;
width: 120px;
height: 30px;
line-height: 30px;
background-color: rebeccapurple;
border-radius: 5px;
color: #fff;
text-align: center;
margin: 10px 0;
} .btn_go {
position: absolute;
left: 0;
top: 90px;
height: 30px;
line-height: 30px;
width: 150px;
background-color: plum;
border-radius: 5px;
text-align: center;
} .hide {
position: absolute;
top: 160px;
left: 0;
display: none;
width: 100px;
height: 30px;
background-color: orange;
}
.btn_top{ overflow: hidden; height: 30px;line-height: 30px; width: 130px; text-align: center; background-color: navy; border-radius: 5px; color: #fff;}
.btn_top_r{ overflow: hidden; height: 30px;line-height: 30px; width: 130px; text-align: center; background-color: rgb(11, 104, 84); border-radius: 5px; color: #fff;}
</style>
</head> <body>
<div class="bd">
<div style="height: 400px; background-color: rgb(33, 107, 172); position: relative;" id="demo">
<div class="btn_animate" id="btnAnimate">点击向左移动</div>
<div class="btn_ho" id="btnHo">点击切换</div>
<div class="hide" id="hide">后显示</div>
<div class="btn_go" id="go">点击变化</div>
</div>
<h2>注意:用animate效果的时候样式一定要定位</h2>
<div style="height: 500px; background-color: rgb(34, 59, 99)" id="floor"></div>
<div style="height: 500px; background-color: orangered"></div>
<div class="btn_top" id="btnTop">scrollTop:top</div>
<div class="btn_top_r" id="btnTop_r">offset().top</div> </div>
<script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function () {
// 让指定元素左右移动
$("#btnAnimate").on("click", function () {
$(this).animate({
left: '+150px'
}, "slow");
});
//在600毫秒内切换段落的高度和透明度
$("#btnHo").on("click", function () {
$("#btnAnimate").animate({
height: 'toggle',
opacity: 'toggle'
}, "slow");
});
//用500毫秒将段落移到left为50的地方并且完全清晰显示出来(透明度为1)
$("#go").click(function () {
$("#hide").animate({
width: "40%",
height: "100%",
fontSize: "20px",
left: 50,
opacity: 'show'
}, 500); });
$("#btnTop").on("click",function(){
//html,body是兼容Firfox与Chrome
$("html,body").animate({"scrollTop":top})
})
$("#btnTop_r").on("click",function(){
$("html,body").scrollTop($("#floor").offset().top - 50)
}) });
</script>
</body> </html>
效果图:

jQuery中animate与scrollTop、offset().top实例的更多相关文章
- jQuery中animate()的方法以及$("body").animate({"scrollTop":top})不被Firefox支持问题的解决
转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/50846678 本文出自[我是干勾鱼的博客] jQuery中animate()的方 ...
- jQuery中animate()方法用法实例
本文实例讲述了jQuery中animate()方法用法.分享给大家供大家参考.具体分析如下: 此方法用于创建自定义动画,并且能够规定动画执行时长.擦除效果.动画完成后还可以地触发一个回调函数. ani ...
- jQuery中animate动画第二次点击事件没反应
jQuery中animate动画第二次点击事件没反应 用animate做点击翻页动画时发现第二次点击事件动画没反应,而第一次点击有动画效果,代码如下: 复制代码 代码如下: $(".page ...
- jQuery中Animate进阶用法(一)
jQuery中animate的用法你了解多少呢?如果仅仅是简单的移动位置,显示隐藏,哦!天哪你在浪费资源!因为animate太强大了,你可以有很多意想不到的用法!让我们一起研究一下吧~~ 首先要了解j ...
- jQuery动画效果animate和scrollTop结合使用实例
CSS属性值是逐渐改变的,这样就可以创建动画效果.只有数字值可创建动画(比如 "margin:30px").字符串值无法创建动画(比如 "background-color ...
- jquery中attr()与prop()函数用法实例详解(附用法区别)
本文实例讲述了jQuery中attr()与prop()函数用法.分享给大家供大家参考,具体如下: 一.jQuery的attr()方法 jquery中用attr()方法来获取和设置元素属性,attr是a ...
- scrollTop,offset().top
1.scrollTop是指滚动条滚动的距离 如果没有出现滚动条,则距离为0 css: <style type="text/css"> *{ margin: 0; pad ...
- jQuery中animate()方法以及$('body').animate({"scrollTop":top})不被Firefox支持问题的解决
$("body").animate({"scrollTop":top}): 只被chrome支持,而不被Firefox支持 $("html" ...
- jQuery中Animate进阶用法(二)
Step Type: Function( Number now, Tween tween )每个动画元素的每个动画属性将调用的函数.这个函数为修改Tween 对象提供了一个机会来改变设置中得属性值. ...
随机推荐
- 【python 】装饰器 (多个参数的函数,带参数的装饰器)【转】
最简单的模板是这样的 #-*-coding:utf-8-*- def outer(func): def inner(): print 'before' func() print 'after' # r ...
- Apache Hadoop 集群安装文档
简介: Apache Hadoop 集群安装文档 软件:jdk-8u111-linux-x64.rpm.hadoop-2.8.0.tar.gz http://www.apache.org/dyn/cl ...
- 关于setConnectTimeout和setReadTimeout的问题
1.问题描述 这几天测试重构后的下载框架,发现在下载过程中如果网络中断或网络较差,个别应用的下载就会阻塞卡住,一直卡在 “正在下载 xx%”. 2.问题排查和定位 思考:网络差不应该报网络异常的错 ...
- 解决Notepad++ Plugin Manager无法加载插件的方法
今天正好安装了Notepad++,结果发现Plugin Manager里插件一个也没有,网上对应的方法都没有,最后无意间看到Plugin Manager Settings 里的提示,试了一下居然成功了 ...
- Linux CentOS修改网卡IP/网关设置
1. 修改对应网卡IP的配置文件 修改以下内容 2. 修改对应网卡的网关的配置文件 vi /etc/sysconfig/network 修改以下内容 3. CentOS 修改DNS 修改以下内容 4. ...
- Django基础学习七之如何配置django+mysql
很久没有更新博客了,也有段时间没有持续性的学习了,感觉堕落了,今天继续开始学习吧 今天主要来学习一下在django下配置mysql的数据库和使用admin用户管理数据库 1.在project中的set ...
- Git忽略规则及.gitignore规则不生效的解决办法(转)
在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以使用修改根目录中 .gitignore 文件的方法(如无,则需自己手工建立此文件).这个文件每一行保存了一个匹配的规则例如: # 此为注 ...
- lombok 介绍及基本使用方法
Lomboz是一个基于LGPL的开源J2EE综合开发环境的Eclipse插件,对编码,发布,测试,以及debug等各个软件开发的生命周期提供支持,支持JSP,EJB等.Lomboz是Eclipse的一 ...
- Zookeeper 源码(五)Leader 选举
Zookeeper 源码(五)Leader 选举 前面学习了 Zookeeper 服务端的相关细节,其中对于集群启动而言,很重要的一部分就是 Leader 选举,接着就开始深入学习 Leader 选举 ...
- AES CFB/OFB/ECB/CBC/CTR优缺点
AES CFB/OFB/ECB/CBC/CTR优缺点 摘自:http://www.metsky.com/archives/418.html 发表时间:2010年05月11 分类: 网络日志 作者: 天 ...