【发布时间】:2014-04-25 23:03:52
【问题描述】:
我正在使用以下标记 (JADE) 使用 AngularJS 和 Foundation 构建分页。
ul.pagination
li.arrow: a «
li(ng-repeat="month in months | orderBy:'_id'" ng-class="month._id === shownMonth ? 'current' : ''")
a(ng-href="#/months/{{month._id}}") {{ month._id | monthid:'short' }}
li.arrow#right-arrow: a »
在 CSS 中,我设置了 overflow: hidden。这让我明白了:
到目前为止完美,但显然这可能会很长。
当用户点击末尾的小箭头符号时,如何进行滚动?
我尝试过像 $(...).animate({left: '-=20'}) 这样的东西,但它只是被忽略了(我猜是因为 Foundation css)。有什么想法吗?
更新
我有一个半有效的解决方案,但它很难看。
我已将ng-show 条件附加到重复的列表项中:
li(ng-repeat="month in months | orderBy:'_id'" ng-class="month._id === shownMonth ? 'current' : ''" ng-show="month._id >= min && month._id <= max")
加载我的数据后我会这样做
$timeout(function() {
var availableWidth = $('ul.pagination').width() - 2 * $('ul li.arrow').width();
var itemWidth = $('li:not(.arrow)').width();
var total = Math.floor(availableWidth / itemWidth);
$scope.min = $scope.shownMonth - Math.floor(total / 2);
$scope.max = $scope.shownMonth + Math.floor(total / 2);
});
然后我基本上只需要在箭头按钮的ng-click 处理程序中调整min 和max。这或多或少是有效的,但由于某种原因,availableWidth 的计算结果比实际可用的空间要小得多 - 大约相差 600 像素!为什么?
【问题讨论】:
标签: css angularjs scroll zurb-foundation angularjs-ng-repeat