【问题标题】:(Angular) Masonry How to get column index of element / next column(角度)砌体如何获取元素/下一列的列索引
【发布时间】:2016-04-06 09:06:59
【问题描述】:

我们正在为 Masonry 元素实现键盘导航,为此我们需要一种方法来将元素置于同一列中的另一个元素之下。有没有办法通过 masonry API(或更好的 AngularJS)访问这些信息(每个项目的 x + y)。

我们在 API / 数据字段中找不到任何内容,剩下的想法基本上是实际读取元素的 x / y 位置并对其进行逆向工程或更改砌体代码。

【问题讨论】:

    标签: javascript angularjs masonry


    【解决方案1】:

    我们选择获取原始数据,即所有小部件上的 x 和 y 位置,并根据 y 坐标在同一列中查找上方或下方的位置,例如:

        aboveIdx = -1
        currentIdx = 0
        while (currentIdx < items.length)
          if(items[currentIdx].position.x is items[$scope.selectedCardIndex].position.x and
             items[currentIdx].position.y < items[$scope.selectedCardIndex].position.y)
            aboveIdx = currentIdx
          currentIdx += 1
        $scope.selectedCardIndex = aboveIdx
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-03
      • 1970-01-01
      • 1970-01-01
      • 2011-05-05
      • 1970-01-01
      • 1970-01-01
      • 2020-01-20
      • 1970-01-01
      相关资源
      最近更新 更多