确定元素的offsetTop的,并设置它的其他元素 [英] Determine offsetTop of an element and set it on other element

查看:732
本文介绍了确定元素的offsetTop的,并设置它的其他元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有是项目的列表。如果点击某个项目anoter视图显示该项目旁边。我想这个观点有相同的offsetTop的项目。我知道如何在jQuery的做到这一点,但无法找到纯angularjs的解决方案。这是我试过到目前为止

There is a list of items. If an item is clicked anoter view is revealed beside the item. I want this view to have the same offsetTop as the item. I know how to do this in jQuery, however cannot find a solution in pure angularjs. This is what I tried so far

top = angular.element('#user'+user.id).prop('offsetTop');
angular.element('#feed-details').css('margin-top', top);

这没有任何影响。任何想法如何在angularjs实现这一目标?

This has no effect. Any ideas how to achieve this in angularjs?

推荐答案

长度都必须有一个单位。 的offsetTop 是一个无单位数字。所以,只需要添加PX来了。

Lengths must have a unit. offsetTop is a unitless number. So just add "px" to it.

这是说,你可以只是做在香草的JavaScript

That said, you could just do it in Vanilla JavaScript:

document.getElementById('feed-details').style.marginTop =
            document.getElementById('user'+user.id).offsetTop+"px";

这篇关于确定元素的offsetTop的,并设置它的其他元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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