Using Angular only, I found the ngView documentation , which recommends using:
<div class="ng-view" autoscroll="true"></div>
But if you want to use a bit of jQuery do the following, add the Scroll Function to all <a>
using .delegate()
so jQuery even matches the <a>
dynamically created by AngularJS:
$("body").delegate("a", "click", function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
});
#altura {
height: 1000px;
width: 100%;
background: #EEE;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="altura"></div>
<a>Todos os Links</a>
And if you want to do it using pure JS only:
var Anchors = document.getElementsByTagName("a");
for (var i = 0; i < Anchors.length ; i++) {
Anchors[i].addEventListener("click",
function() {
document.body.scrollTop = 0;
},
false);
}
#altura {
height: 1000px;
width: 100%;
background: #EEE;
}
<div id="altura"></div>
<a>Todos os Links</a>
Another solution using Pure JS:
#altura {
height: 1000px;
width: 100%;
background: #EEE;
}
<div id="altura"></div>
<a onclick="location.href='#altura'">Todos os Links</a>