使用链接在div内滚动div? [英] Scrolling div inside div using link?

查看:124
本文介绍了使用链接在div内滚动div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想滚动到基于 id 当点击链接时div的顶部位置...
如果链接旁边点击所以div idltvmove / scroll以上图片来描述我的目的。
>

谢谢

解决方案

您可以使用jQuery的 scrollTop 函数

  $('#点击(函数(e){
e.preventDefault();
$('#divId')。scrollTop(0);
});

如果你想让它像一个幻灯片一样,可以用 .animate

  $('#divId')。stop()。 animate({scrollTop:0px}); 

如果您想让某个div跳到顶部,您需要制定出它的yfefest,然后使用它作为scrollTop px



例子


i want to scroll to top position of div based id when link clicked... if link beside click so div id "ltv" move / scroll to top..

this my picture to describe my purpose

if anyone knows how to do this, or can give me a good starting point I'd appreciate it.

Thanks

解决方案

you can use jQuery's scrollTop function

$('#ltv').click(function(e) {
  e.preventDefault();
  $('#divId').scrollTop(0);
});

If you want this to be like a slide up to the top, you can use it with .animate:

  $('#divId').stop().animate({ scrollTop: "0px" });

if you are wanting a certain div to go to the top, you are gouing to have to work out its y offest and then use that as the scrollTop px

Example

这篇关于使用链接在div内滚动div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆