Jquery Mobile返回按钮滚动到顶部 [英] Jquery Mobile go back button scrolls to top

查看:229
本文介绍了Jquery Mobile返回按钮滚动到顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Jquery Mobile网站上
我正在使用href作为后退按钮;

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.

有没有解决方案?

推荐答案

解决方案



我有这个问题我用 iSroll

从PageA转到PageB时,将PageA的滚动位置保存在变量中。

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

执行此操作修改iscroll.js并在scrollTo下添加getScrollY方法,如下所示

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();

并在返回到PageA时设置滚动位置,我在PageB的pagehide事件中执行此操作

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.

如果您想了解有关此主题的更多信息,请查看此 文章 ,您还可以找到工作示例。

If you want to find out more about this topic take a look at this article, you will also find working examples.

这篇关于Jquery Mobile返回按钮滚动到顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆