locorecto
locorecto

Reputation: 1203

Prevent auto-scrolling to top before sliding to new page JqueryMobile

I have several collapsible blocks (divs) in my page with listviews inside them. The lists are pretty long (about 100-200 elements each.) When I un-collapse a block, scroll down a page, and click/tap one of the element in the list, the page scrolls to the top before sliding to the next page.

This behavior is somehow annoying and doesn't look good. I there any way to prevent this behavior?

If you have any additional question about my post, don't hesitate to ask me.

Thanks in advance.

Upvotes: 3

Views: 1424

Answers (1)

imp
imp

Reputation: 470

If you use a link with "#" as href, it will jump up to the top of the page, however if you add "return false;" after the exectution of your code, it won't jump up. Example:

<script>
function test(){
alert('It works!'); // Just a simple function
}
</script>

<!-- Div to make the page scrollable -->

<div style="margin-top:1000px;height:1px;width:1px;"></div>

<a href="#" onClick="test(); return false;">Yay</a>
<!-- Triggering the test function and not jumping up to the top -->

I'm not sure if this is what you were thinking about though.

Upvotes: 1

Related Questions