我有一个自定义的角度指令,因此当您单击该元素时它将向下移动:angular.module('plunker',[])
.controller('AnimateCtlr', function(){
})
.directive('clickToAnimate', function(){
var linker = function(scope, element, attrs) {
element.bind('click', function(){
console.log('moving');
console.log( $( this).text() );
$(this).animate({top: '+=150'});
});
};
return {
restrict: 'AE',
replace: false,
scope: {
direction : '@'
},
link: linker
};
});
所有console.log都可以检测到单击事件,但是问题是div根本没有移动。这里有什么问题?
Plunker在这里:http ://plnkr.co/edit/j1OMiZFrar71P742dY6W?p=preview
如果您将位置设置为绝对位置,则应该可以正常工作
JS:
angular.module('plunker', [])
.controller('AnimateCtlr', function(){
})
.directive('clickToAnimate', function(){
var linker = function(scope, element, attrs) {
element.bind('click', function(){
console.log('moving');
console.log( $( this).text() );
$(this).css({position: 'absolute'}) // can be done right here! But belongs in your CSS really.
$(this).animate({top: '+=150'}, 300, function(){
console.log('complete')
});
});
};
return {
restrict: 'AE',
replace: false,
scope: {
direction : '@'
},
link: linker
};
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句