我有以下代码:
指数
<div id="app" ng-controller="AppCtrl">
<div id="container" ng-controller="PageCtrl">
<div ng-repeat="page in pages" id="{{page.prop_id}}">
<ng-include src="page.template" />
</div>
</div>
JSON
[
{
"prop_id" : "FORD0109",
"prop_title" : "Lorem Ipsum",
"prop_postcode" : "",
"prop_price" : "",
"prop_image" : "",
"prop_desc" : "Lorem Ipsum",
"template" : "views/prop_no_thumbs.html",
"info_image" : "",
"duration" : "4000"
}
]
控制器
var presentation = angular.module("Presentation", ['ngResource']);
function AppCtrl($scope, $http) {
$http.get('json/pages.json').success(function (data) {
$scope.pages = data;
});
$scope.animateToId = function (id, container, duration) { //the id to animate, the easing type
id = "#" + id;
var $container = $(container); //define the container to move
var left = $(id).position().left;
var animSpeed = 2000; //set animation speed
var ease = "easeOutQuart";
$container.stop().animate({"left":-(left)}, animSpeed, ease);
}
}
function MenuCtrl($scope) {
//placeholder for Menu actions
}
function PageCtrl($scope) {
//placeholder for Page actions
}
当 a 调用 a 上的animateToID()
函数时,上述所有代码都可以正常工作ng-click
。
我需要它来使用页面 JSON 文件中出现的持续时间值自动开始滑过模板。JSON 中的所有项目都完成后,通过同一个数组重新开始。