Foros de discusión
Setting scrollTop
Jan Tošovský, modificado hace 8 años.
Setting scrollTop
Liferay Master Mensajes: 566 Fecha de incorporación: 22/07/10 Mensajes recientes
Dear All,
I am failing to implement the following jQuery snippet in pure AUI
The purpose of this code is to scroll the top of the page below the floating toolbar to avoid hidding the requested anchor.
I don't insist on that animation.
Currently I have
I have no idea how to scroll properly.
Thanks, Jan
I am failing to implement the following jQuery snippet in pure AUI
var hash = window.location.hash;
if(hash){
var targetOffset = $(hash).offset().top - 190;
$('html,body').animate({scrollTop: targetOffset}, 200);
return false;
}
The purpose of this code is to scroll the top of the page below the floating toolbar to avoid hidding the requested anchor.
I don't insist on that animation.
Currently I have
AUI().ready(function(A) {
var hash = window.location.hash;
if (hash) {
hash += ",a[name='" + hash.substring(1) + "']";
var offset = A.one(hash).getXY();
alert(offset);
// A.one(hash).setXY(offset[0], offset[1] - 190);
// A.one('body').setAttribute('scrollTop', offset[1] - 190);
}
});
I have no idea how to scroll properly.
Thanks, Jan
Jan Tošovský, modificado hace 8 años.
RE: Setting scrollTop (Respuesta)
Liferay Master Mensajes: 566 Fecha de incorporación: 22/07/10 Mensajes recientes
There were two problems in my code.
- scrollTop is not an attribute
- scrollTop value is not set on body or html in my case, but on specific container
<aui:script use="aui-base">
AUI().ready(function(A) {
var hash = window.location.hash;
if (hash) {
var scroller = A.one('#scroller');
scroller.set('scrollTop', scroller.get('scrollTop') - 80);
}
});
</aui:script>