Jquery Mobile go back button scrolls to top

0 votes

In my Jquery Mobile website I am using href for back button like;

 <a id='{0}' class='{1}' href='/' data-role=""button"" data-icon=""arrow-l"" data-transition=""slide"" data-direction=""reverse"">

but if I have scroll on first page, back button jumps back to top again. First page does not stay on same position.

Is there any solution for this?

Aug 4 in Web Development by gaurav
• 17,580 points
13 views

1 answer to this question.

0 votes

I had this issue i fixed it using iSroll

While going from PageA to PageB save the scroll position of PageA in a variable.

to do this modify the iscroll.js and add getScrollY method under scrollTo like this

        scrollTo : function(x, y, time, relative) {
            var that = this, step = x, i, l;

            that.stop();

            if (!step.length)
                step = [{
                    x : x,
                    y : y,
                    time : time,
                    relative : relative
                }];

            for ( i = 0, l = step.length; i < l; i++) {
                if (step[i].relative) {
                    step[i].x = that.x - step[i].x;
                    step[i].y = that.y - step[i].y;
                }
                that.steps.push({
                    x : step[i].x,
                    y : step[i].y,
                    time : step[i].time || 0
                });
            }

            that._startAni();
        },
        getScrollY : function() {

            var that = this;

            return that.y;

        },

Now save the current position before page change like this

curScrollPos = myScroll.getScrollY();

And set the scroll position while going back to that PageA, i am doing this on pagehide event of PageB

myScroll.scrollTo(0, curScrollPos, 1);
myScroll.refresh();

This way i solved my issue, hope this helps.

answered Aug 5 by rajatha
• 7,040 points

Related Questions In Web Development

0 votes
0 answers

How to check radio button is checked using JQuery?

I have two radio buttons in one ...READ MORE

Jun 29 in Web Development by gaurav
• 17,580 points
12 views
0 votes
0 answers

How to scroll to top of page with JavaScript/jQuery?

Is there a way to control browser ...READ MORE

Jul 1 in Web Development by gaurav
• 17,580 points
31 views
0 votes
0 answers

how to trigger on jquery.smart wizard Finish button?

Iam very new in jquery. here is ...READ MORE

Jul 19 in Web Development by gaurav
• 17,580 points
46 views
0 votes
0 answers
0 votes
1 answer

Horizontal scrolling and vertical scrolling in JqueryMobile

I'll go through code's main parts for ...READ MORE

answered Jun 21 in JQuery by rajatha
• 7,040 points
24 views
0 votes
0 answers

Page Reload/Refresh executes $(document).ready() on every page in jQuery Mobile

My jQuery mobile applications consists of multiple ...READ MORE

Jul 22 in Web Development by gaurav
• 17,580 points
15 views
0 votes
1 answer

What is jQuery?

Hey, jQuery is a fast and concise JavaScript ...READ MORE

answered Feb 14, 2020 in JQuery by kartik
• 37,500 points
308 views
0 votes
1 answer

Uncaught TypeError: Cannot read property 'msie' of undefined - jQuery tools

Hello, Use the following script tag in your ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,740 points
8,840 views
0 votes
1 answer

How to change the jquery mobile flip switch state from code

I've examined the page you posted and ...READ MORE

answered Aug 1 in Web Development by rajatha
• 7,040 points
14 views
0 votes
1 answer

How to place images using jQuery masonry plugin to start

You were just missing a css class that adjusts ...READ MORE

answered Jun 22 in Web Development by rajatha
• 7,040 points
9 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP