Pregunta

My question is pretty much the same as this one except that I'm using jQuery Mobile 1.0. The entire project has been written and I don't want to have to update it to 1.3.2 just to get this scroll feature to work with my collapsible set. Is there anything I can use from the answer provided in the linked question that can be adapted to 1.0?

Thanks

¿Fue útil?

Solución

Upgrading isn't required in order to have the scroll working. Only the way of listening to expand event is different.

Bind

$(".ui-collapsible").bind("expand", function () {
  /* scroll */
});

Delegate

$(document).delegate(".ui-collapsible", "expand", function () {
  /* scroll */
});

Scroll

var position = $(this).offset().top;

/* scroll with animation */
$("html, body").animate({
    scrollTop: position
});

/* scroll without triggering scroll event */
$.mobile.silentScroll(position);

Demo

Otros consejos

Thank you so much! Makes perfect sense now. And for those reading this post, I also added an offset to the top like this:

var topoffset = 50;
var position = $(this).offset().top - topoffset;

/* scroll with animation */
$("html, body").animate({
scrollTop: position
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top