문제

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

도움이 되었습니까?

해결책

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

다른 팁

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
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top