点击滚动到指定元素位置

 $(document).ready(function (){
     $("#scroll").click(function (){
        $(‘html, body‘).animate({
            scrollTop: $("#div").offset().top
        }, 500);
    });
});

  使用scrollTop方法,加上一点延时动画(animate)

原文地址:https://www.cnblogs.com/wangyongx/p/10932253.html

时间: 2024-08-30 17:35:10

点击滚动到指定元素位置的相关文章

使页面滚动到指定元素+优化+API介绍(JS动画)

前言 当页面最上部有顶部菜单是,使用锚点跳转的方法很容易挡住想要呈现的内容(如下图技能两个字被挡住了一半),为避免出现这样的问题,故滚动到指定元素使用用JS的方法来实现. 1  使用的API简介 document.querySelectorAll preventDefault currentTarget getAttribute document.querySelector offsetTop window.scrollTo 2  初版 代码及思路如下: //1 点击导航跳到指定位置第一步,获取

滚动到指定元素的id处+当元素出现在浏览器显示区域就会自动加载

//滚动到指定元素的id处 如:$("#Exam82") function Jump() { var scroll_offset = $("#Exam82").offset();  //得到Exam82这个div层的offset,包含两个值,top和left $("body,html").animate({ scrollTop: scroll_offset.top  //让body的scrollTop等于Exam82的top,就实现了滚动 },

微信小程序点击滚动到指定位置

公司项目要做一个类似微信通讯录导航的效果,点击右侧字母页面滚动到相应位置. 因为微信小程序没有dom概念,所以不能使用锚点,也不能直接获取对应字母相对页面的偏移位置.此时只能使用小程序创建对象实例的API获取节点信息: let query = wx.createSelectorQuery().in(this); query.selectViewport().scrollOffset() query.select("#Nav").boundingClientRect(); query.s

tableView刷新指定的cell 或section和滚动到指定的位置

转自:http://blog.csdn.net/tianyou_code/article/details/54426494 //一个section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2]; [tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic]; //一个cell刷新 NSIndexPath *index

页面滚动到指定元素区域

该代码段可将指定元素平滑滚动到浏览器窗口的可见区域. const smoothScroll = element => document.querySelector(element).scrollIntoView({ behavior: 'smooth' }); smoothScroll('#fooBar'); smoothScroll('.fooBar'); 原文地址:https://www.cnblogs.com/zhenguo-chen/p/12032165.html

如何通过JQuery将DIV的滚动条滚动到指定的位置

这里有一个方法可以将DIV的滚动条滚动到其子元素所在的位置,方便自动定位. var container = $('div'), scrollTo = $('#row_8'); container.scrollTop( scrollTo.offset().top - container.offset().top + container.scrollTop() ); // Or you can animate the scrolling: container.animate({ scrollTop:

jquery滚动到指定元素,模仿锚点

html 1 <div class="pd-nav"> 2 <div class="n-item active"> 3 保险服务 <i></i> 4 </div> 5 <div class="n-item " id="bzjh1"> 6 保障计划 7 <i></i> 8 </div> 9 <div class=&q

Div 滚动条滚动到指定的位置

<!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-

js滚动到指定元素

代码: <style> button{ position: fixed; bottom: 0; right: 0; } </style> <button id="button">click to see</button> <p>1</p> <p>1</p> <p>1</p> <p>1</p> <p>1</p> <p