Angularjs观看元素切换帧的变化
Angularjs Watching A change in Elements switch frames
我有一个使用div的旋转木马。我想看看它是哪个div,并相应地切换页面的其余部分。。。
这是我尝试rootscope的控制器中的一些代码。candidateview是一个ng show,如果它是第一个div.,我希望它是真的
self.changedWatcher = function(){
var items = angular.element(document.querySelectorAll(".item"));
$scope.$watch(items, function() {
for (var i = 0; i < items.length; i++) {
var wrappedItem = items[i];
if (wrappedItem.hasClass('active')) {
if (i == 0) {
alert("hi");
$rootScope.candidateView = true;
} else if (i == 1) {
$rootScope.candidateView = false;
alert("hi2");
} else {
$rootScope.candidateView = false;
alert("hi3");
}
}
}
});
}
self.changedWatcher();
以上这些都不起作用——似乎只起了几秒钟的作用,再也不会着火了。
这是HTML:
<div id="myCarousel" class="carousel slide" data-ride="carousel"
data-interval="false" ng-controller='MainController as ctrl'>
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="item active">
first item...
</div>
<div class="item">
another item...
</div>
<div class="item">
... an item
</div>
<a class="left carousel-control" href="#myCarousel" role="button"
data-slide="prev"> <span class="glyphicon glyphicon-chevron-left"
aria-hidden="true"></span> <span class="sr-only">Previous</span>
</a> <a class="right carousel-control" href="#myCarousel" role="button"
data-slide="next"> <span
class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<!-- /.carousel -->
<!--below is div to show -->
<div class="container viewpoint" ng-show='candidateView'></div>
我还试图将ng-click链接到一些javascript,但失败了,因为当你点击时,它不会足够快地更改carousel中的活动div,而且总是被延迟。
编辑------------------------------
我添加了一些加法和减法函数来跟踪转盘的currentFrame。。。但不幸的是,如果你双击它会打乱计数,因为帧需要转换时间。。。我试着用超时禁用按钮,但这冻结了一切。。。
$rootScope.currentFrame = 0;
self.changeFrame = function(value) {
$rootScope.currentFrame = value;
}
self.addFrame = function(value) {
$rootScope.currentFrame += value;
if ($rootScope.currentFrame > 2)
$rootScope.currentFrame = 0;
if ($rootScope.currentFrame < 0)
$rootScope.currentFrame = 2;
}
编辑方法的问题:双击会打乱计数。。。ng禁用超时也会导致转盘等待。
$rootScope.currentFrame = 0;
self.changeFrame = function(value) {
$rootScope.currentFrame = value;
}
self.addFrame = function(value) {
$rootScope.disable = true;
$timeout(function() {
$rootScope.currentFrame += value;
if ($rootScope.currentFrame > 2)
$rootScope.currentFrame = 0;
if ($rootScope.currentFrame < 0)
$rootScope.currentFrame = 2;
}, 500);
$rootScope.disable = false;
}
我没有使用ngwatch,而是挂接了carusole中的一个事件。阅读您用于此信息的carusole的参考资料。
相关文章:
- 根据元素高度和宽度的百分比变化增加或减少字体大小
- 一个变化:在加载图像之前加载元素
- 如何在呈现页面后使用 Java 脚本检测 dom 元素值的值是否有任何变化(例如,任何输入或复选框值更改)
- 在照片库中的两个元素之间切换样式会发生变化
- CSS.滚动后元素位置发生变化
- 当元素的高度发生变化时,如何获取元素的高度
- 如何观察聚合物元素属性值从索引.html的变化
- 一旦 JavaScript 中任何 HTML 元素的值发生变化,就会更新画布
- 如何模拟元素的真实变化
- 有没有一种简单的方法来检测容器元素中的焦点变化
- 观察父元素上指令的 ngModel 值变化
- 将元素的宽度设置为等于监视器大小,而不会在缩放时发生变化
- jQuery:记录数组中的元素变化,并通过索引检查它是如何变化的
- 检测元素高度变化,如果太小则隐藏
- 如何使jquery函数与动态变化的元素一起工作
- Angularjs观看元素切换帧的变化
- 当聚合物元素中的布尔属性发生变化时,如何用sort重新运行dom repeat
- 使用JavaScript,这样当点击图像时,另一个元素's的位置发生了变化
- 如何检测primefaces日历元素的变化
- 更新元素以显示" contentteditable& quot;中的实时变化元素