scrollTop如何实现click后页面过渡滚动到顶部
用JS操作,body元素的scrollTop
var getTop = document.getElementById("get-top");
var head = document.getElementById("head");
getTop.onclick = function () {
var time = setInterval(function () {
document.body.scrollTop = document.body.scrollTop - ;
if (document.body.scrollTop === ) {
clearInterval(time);
}
}, );
};
下面不确定,网上找的没实验;
$(window).scroll(function(){
if ($(window).scrollTop()>){
$("#backTop").fadeIn();
}
else
{
$("#backTop").fadeOut();
}
});
//当点击跳转链接后,回到页面顶部位置
$("#backTop").click(function(){
$('body,html').animate({scrollTop:},);
return false;
});
});
点击页面回到底部或者指定位置:
// $(window).scroll(function () {
// var scrollTop = $(this).scrollTop();
// var scrollHeight = $(document).height();
// var windowHeight = $(this).height();
// console.log(scrollTop+','+scrollHeight+','+windowHeight)
// if ((scrollTop + windowHeight) / scrollHeight > 0.99) {
// $("#callMe").css("display", 'none')
// } else {
// $("#callMe").css("display", 'block')
// }
// });
$(".order").click(function(){
var height=document.body.offsetHeight;
// $(window).scrollTop(height,3000);
$('html,body').animate({scrollTop: height}, )
})
滚动到顶部:
$('.scroll_top').click(function(){$('html,body').animate({scrollTop: '0px'}, );});
滚动到指定位置:
$('.scroll_a').click(function(){$('html,body').animate({scrollTop:$('.a').offset().top}, );});
完整事例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js平滑滚动到顶部、底部、指定地方</title>
<script type="text/javascript" src="http://cdn.staticfile.org/jquery/2.1.1-rc2/jquery.min.js"></script>
<style>
.box{ height:200px; width:%; background:#ccc; margin:10px ;}
.location{ position:fixed; right:; bottom:10px; width:20px; background:#FFC; padding:5px; cursor:pointer;color:#};
</style>
</head>
<body>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box a">产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍</div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box bottom"></div>
<div class="location">
<p class="scroll_top">返回顶部</p>
<p class="scroll_a">产品介绍</p>
<p class="scroll_bottom">滑到底部</p>
</div>
<script type="text/javascript">
jQuery(document).ready(function($){
$('.scroll_top').click(function(){$('html,body').animate({scrollTop: '0px'}, );});
$('.scroll_a').click(function(){$('html,body').animate({scrollTop:$('.a').offset().top}, );});
$('.scroll_bottom').click(function(){$('html,body').animate({scrollTop:$('.bottom').offset().top}, );});
});
</script>
</body>
</html>
scrollTop如何实现click后页面过渡滚动到顶部的更多相关文章
- css3如何实现click后页面过渡滚动到顶部
var getTop = document.getElementById("get-top"); var head = document.getElementById(" ...
- 移动端和PC端弹出遮罩层后,页面禁止滚动的解决方法及探究
PC端解决方案 pc端的解决思路就是在弹出遮罩层的时候取消已经存在的滚动条,达到无法滚动的效果. 也就是说给body添加overflow:hidden属性即可,IE6.7下不会生效,需要给html增加 ...
- 移动端touch事件影响click事件以及在touchmove添加preventDefault导致页面无法滚动的解决方法
这两天自己在写一个手机网页,用到了触屏滑动的特效,就是往右滑动的时候左侧隐藏的菜单从左边划出来. 做完之后在手机原生浏览器中运行正常,但在QQ和微信中打开,发现touchmove只会触发一次,而且to ...
- WebForm 回传后如何保持页面的滚动位置
转载自 http://www.cnblogs.com/renjuwht/archive/2009/06/17/1505000.html 默认情况下,ASP.NET页面回传到服务器后,页面会跳回顶部.对 ...
- input禁止输入后,触发事件,在苹果手机的页面会滚动
在vue中,<input type="text" readonly="readonly" @click=""/>,点击跳转页面. ...
- h5之scrollIntoView控制页面元素滚动
如果滚动页面也是DOM没有解决的一个问题.为了解决这个问题,浏览器实现了一下方法,以方便开发人员如何更好的控制页面的滚动.在各种专有方法中,HTML5选择了scrollIntoView()作为标准方法 ...
- h5页面弹窗滚动穿透的思考
可能我们经常做这样的弹窗对吧,兴许我们绝对很简单,两下搞定: 弹窗的页面结构代码: <!-- 弹窗模块 引用时移除static_tip类--> <div class="ma ...
- 简易页面场景滚动的jquery插件
(function($){ $.extend($.fn, { scene_scroll:function(arg_obj){ // 参数检测 // 场景数组 var $scene_arr = arg_ ...
- 跳出弹窗页面禁止滚动(PC端和手机端)
pc端如何实现 1.当弹窗显示时,为body元素添加属性:overflow:hidden, 当关闭弹窗时移除该属性即可2.在弹窗的div上设置 @scroll.stop.prevent 3.前端页面弹 ...
随机推荐
- 如何利用python制作微信好友头像照片墙?
这个不难,主要用到itchat和pillow这2个库,其中itchat用于获取微信好友头像照片,pillow用于拼接头像生成一个照片墙,下面我简单介绍一下实现过程,代码量不多,也很好理解,实验环境wi ...
- iOS开发 - 多线程实现方案之NSThread篇
NSThread API //类方法:创建一个线程 + (void)detachNewThreadWithBlock:(void (^)(void))block API_AVAILABLE(macos ...
- 分布式通信-tcp/ip socket
Socket通讯的过程 Server端Listen(监听)某个端口是否有连接请求,Client端向Server 端发出Connect(连接)请求,Server端向Client端发回Accept(接受) ...
- 洛谷 P1053 篝火晚会
https://www.luogu.org/problemnew/show/P1053 错误记录:判-1的时候出了些问题(比如只判了图是否连通):数组没清空 #include<cstdio> ...
- asp.net多文件上传
文件上传简单实现是非常容易的,但是想要更高的要求,比如通过ajax上传文件.一次上传多个文件.文件比较大等等,这里面的坑就不是很容易填(对于新手来说).因此在这里我准备通过ajax实现多文件上传.在开 ...
- C# readonly和const的区别
什么是静态常量(Const)和动态常量(Readonly) 先解释下什么是静态常量(Const)以及什么是动态常量(Readonly). 静态常量(Const)是指编译器在编译时候会对常量进行解析,并 ...
- 09通过winfrom实现简单的播放音、视频
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- CF1060D Social Circles
思路: 贪心.既然每个人的左边是其他人的右边,每个人的右边是其他人的左边,那么使重叠的部分最多即可. 实现: #include <bits/stdc++.h> using namespac ...
- github小技巧之Creating a pull request 创建 pull 请求
创建一个 pull 请求是为了协作更改存储库.这些变化会产生一个分支,它确保主分支保持干净整洁. 与commits提交是不同的,提交是fork之后的一种操作. 在你可以打开一个 pull 请求之前,您 ...
- Spring 配置定时器(注解+xml)方式—整理
一.注解方式 1. 在Spring的配置文件ApplicationContext.xml,首先添加命名空间 xmlns:task="http://www.springframework.or ...