我需要从控制器内部滚动到一个元素。
使用du-smooth-scroll
和href="#invoice-wrapper"
可以在角度html页面内的按钮和其他元素上正常工作。
<button du-smooth-scroll href="#invoice-wrapper">
<!--Invoice Form-->
<div id="invoice-wrapper"></div>
有没有办法从控制器内激活同样的东西?
vm.scrollTo = (element) => {
du-smooth-scroll(element)
}
或类似的东西?有办法吗?
答案 0 :(得分:1)
您可以使用du-smooth-scroll
并从指令中捕获事件,但这只有在您的视图中出现// in your controller
vm.scrollTo = (element) => {
$scope.$broadcast("du-smooth-scroll", element);
};
// in your directive
$scope.$on("du-smooth-scroll", function (element) {
// call your function that does that scroll
});
时才有效。
scrollTo
我想要另一种方法我建议创建一个全局$rootScope.scrollTo = function (element) {
// do the scroll thing
};
函数,可以在你的指令和控制器或任何地方使用
$rootScope.scrollTo(element)
然后只需在控制器和指令中调用import flash.events.MouseEvent;
import flash.display.MovieClip
var numbertext:Number = 0;
var MyClip:MovieClip = new MovieClip();
submitbtn.addEventListener(MouseEvent.CLICK, testPassword);
function testPassword(e:MouseEvent):void {
if (numbertext == 903) {
MyClip.gotoAndPlay(903);
}
else {
MyClip.gotoAndPlay(200);
}
}
。
答案 1 :(得分:1)
您可以像这样使用内置$anchorScroll:
$anchorScroll('invoice-wrapper');