scrollTop仅在首次点击时有效

编程入门 行业动态 更新时间:2024-10-27 09:41:02
本文介绍了scrollTop仅在首次点击时有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我有一个amcharts图形,当我单击图形中的条形图时,它旁边的div滚动到该条形图中的数据.我的问题是,第一次点击后,我随时都点击它,有时甚至是一个随机位置.我希望能够在单击时滚动到每个数据.

So I have an amcharts graph, and when I click on a bar in the graph, a div next to it scrolls to that data from the bar. My problem is when I click anytime after the first time it goes to the top or sometimes a random position. I want to be able to scroll to each piece of data when clicked.

这是我的scrollTo方法的代码:

This is my code for the scrollTo method:

"listeners": [{ "event": "clickGraphItem", "method": function (event) { var buildNumber = event.item.category; var id = '#buildNumber' + buildNumber; var buildFailureObject = $('#buildNumber' + buildNumber); $('#infodiv').animate({ scrollTop: $(buildFailureObject).position().top - 20 }, 2000); } }]

信息div是滚动发生的地方.为了明确起见,第一次单击可以使我进入"buildFailureObject",但是接下来的单击要么使我回到infodiv的顶部,要么有时是一个随机的靠近地点的地方.

The info div is where the scrolling happens. To clarify, the first click works and takes me to the "buildFailureObject", but the next clicks either take me back to the top of the infodiv or sometime a random close by spot.

我已经看过接近我的问题,并且preventDefault并没有帮助我,也没有返回false.

I have looked at questions close to mine and preventDefault has not helped me nor has return false.

感谢您提供的任何帮助.

Thank you for any help you can provide.

推荐答案

好,所以我想出了答案,我需要这样做:

Ok so I figured out the answer, I needed this:

$('#infodiv').animate({scrollTop:($('#infodiv').scrollTop()+ $(buildFailureObject).position().top -20)},2000);

$('#infodiv').animate({scrollTop:($('#infodiv').scrollTop() + $(buildFailureObject).position().top -20)}, 2000);

更多推荐

scrollTop仅在首次点击时有效

本文发布于:2023-11-13 21:37:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585387.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:首次   scrollTop

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!