木头
木头
  • 发布:2015-01-05 16:31
  • 更新:2016-07-01 09:44
  • 阅读:6262

window.scrollTo(0,0); 在H5+ 中无效吗?

分类:HBuilder

window.scrollTo(0,0); 在H5+ 中无效吗?

现在滚动条是用 div overflow-y: scroll; 实现的,
求教,如何实现点击按钮回到顶部?

2015-01-05 16:31 负责人:无 分享
已邀请:
木头

木头 (作者)

顶起~

  • sf

    document.body.scrollTop = 0;

    2015-01-05 17:54

  • 木头 (作者)

    回复 sf:测试了,无效!

    2015-01-05 18:38

木头

木头 (作者)

怎么没人回答?

bequite

bequite - DTD

window.scrollTop = 0 不起作用吗

Joshua

Joshua

在 ios 上 获取document.documentElement.scrollTop 、 document.body.scrollTop 、window.pageYOffset都是0,郁闷。现在返回顶部,做不了,而且在ios上,<a href="#"></a>也没效果。
但在android都正常

DCloud_UNI_FXY

DCloud_UNI_FXY

页面整个代码贴一下

  • Joshua

    <!DOCTYPE html>

    <html>


    <head>

    <meta charset="utf-8">

    <title>专业清尾货</title>

    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">

    <meta name="apple-mobile-web-app-capable" content="yes">

    <meta name="apple-mobile-web-app-status-bar-style" content="black">


    <link rel="stylesheet" href="../css/mui.min.css">

    <link rel="stylesheet" href="../css/app.css">

    <script src="../js/mui.min.js"></script>

    <script src="../js/handlebars-v2.0.0.js" type="text/javascript" charset="utf-8"></script>

    <script src="../js/app.js"></script>

    <style>

    html,

    body {

    background-color: #efeff4;

    }

    .title {

    margin: 20px 15px 10px;

    color: #6d6d72;

    font-size: 15px;

    }

    .mui-search input{

    background: none;

    border: 1px solid #fff;

    color: #fff;

    text-align: left;

    }

    </style>

    </head>


    <body>

    <div class="tool-bar search-bar mui-clearfix">

    <div class="tool-bar-wrapper mui-pull-left">

    <a class="byg_iconfont icon-filter mui-pull-left filter-btn" id="filter-btn"></a>

    <!--<a class="mui-btn mui-btn-link mui-pull-right" id="search-btn">搜索</a>-->

    </div>

    <div class="mui-content-padded" id="search-btn">

    <div class="mui-input-row mui-search">

    <input type="button" class="mui-btn mui-btn-block mui-btn-outlined">

    <span class="mui-placeholder"><span class="mui-icon mui-icon-search"></span>寻找商品</span>

    </div>

    </div>

    </div>

    <div id="pullrefresh" class="mui-scroll-wrapper">

    <div class="mui-scroll">

    <ul class="mui-table-view mui-grid-view mui-grid-9" id="item-wrapper">

    <li class="mui-table-view-cell mui-media mui-col-xs-6"></li>

    <li class="mui-table-view-cell mui-media mui-col-xs-6"></li>

    </ul>

    </div>

    </div>

    </div>

    <a id="scrollTo" class="top mui-btn byg_iconfont">&#xe69e;</a>

    <p class="content-none"></p>

    <div class="content-offline">

    <h3>亲,您的手机网络不太顺畅喔~</h3>

    <p class="tips">请检查您的手机是否联网</p>

    <p><button class="mui-btn" id="reload">重新加载</button></p>

    </div>

    <script id="list-tpl" type="text/x-handlebars-template">

    {{#each this}}

    <div class="item-box">

    <a id="{{leftoverId}}" class="mui-navigate-right pic-box" href="template/leftoverDetail.html">

    <img src="{{host}}/getImg-index-{{imgId}}-200-0.png" alt="" />

    </a>

    <p>

    <span class="shopName">{{shopName}}</span>

    <span class="mui-badge"><samp class="byg_iconfont byg-icon-s fav">&#xf0004;</samp><samp class="num">(10)</samp></span>

    </p>

    <p class="call"><a class="mui-icon mui-icon-phone" href="tel:{{telephone}}">{{telephone}}</a>

    </p>

    </div>

    {{/each}}

    </script>

    </body>


    </html>

    2015-01-20 17:55

  • DCloud_UNI_FXY

    在ios里边,我们的下拉刷新是区域滚动,你需要调用mui('#pullrefresh').pullRefresh().scrollTo(0,0);来滚动到顶部

    2015-01-20 18:02

Joshua

Joshua

是不是因为ios上的滚动条是模拟的。

all_in

all_in

楼主怎么解决的啊

DCloud_UNI_FXY

DCloud_UNI_FXY

如果是ios上使用了scroll控件。那么调用mui('#scroll').scrollTo(0,0,200);//x,y,time

  • topSWdept

    没有用啊?

    2015-09-09 21:09

  • topSWdept

    [ERROR] : TypeError: undefined is not a function (evaluating 'mui('#refreshContainer').scrollTo(0,0,100)')

    2015-09-09 21:11

  • DCloud_UNI_FXY

    回复 topSWdept:mui('#refreshContainer').scroll().scrollTo(0,0,100)

    2015-09-10 14:17

心如月

心如月

那如果这个页面没有使用scroll控件呢,该怎么办

  • 杰哥seo

    请问这个问题解决了吗

    2016-11-15 13:57

该问题目前已经被锁定, 无法添加新回复