【问题标题】:scroll to specific element on mobile phone doesn't work滚动到手机上的特定元素不起作用
【发布时间】:2017-12-16 09:36:47
【问题描述】:

我有一个我想要的点击事件,当它被触发时,窗口滚动到特定坐标

<div class="col-xs-12 responsiveView">
<div class="row" id="selectedDay"></div>
<div class="responsiveOrders"></div>
<div class="responsiveNewOrders row">
    <div class="orderMenuTitle">

    </div>
</div>

,到目前为止,我参考jQuery scroll to elementHow to go to a specific element on page? 使用了以下代码

$('html').animate({
   scrollTop: $(".responsiveView").offset().top
}, 1000);

var x = $('.responsiveView').offset().left;
var y = $('.responsiveView').offset().top;
window.scrollTo(x,y);

animate 在浏览器的响应式视图上运行良好,但 它们都不能在实际的 iphone 上运行。 我搜索了很多,这不是重复的! 提前感谢您的帮助。

【问题讨论】:

标签: javascript jquery html


【解决方案1】:

我尝试了同样的方法

$('html, body').animate({
     scrollTop: $(".responsiveView").offset().top
}, 1000);

它成功了,问题是我试图在特定框(带有 responsiveView 类的元素)完全加载之前滚动页面,所以我将上面的代码放在我的函数的回调中(当数据加载和框完全可见)并且它有效。

【讨论】:

    【解决方案2】:

    答案可能对某些人有用,但如果对您不起作用,您可以使用setTimeOut() 来执行该功能。

      setTimeout(function(){
         $('html').animate({
         scrollTop: $(".responsiveView").offset().top
         }, 1000)
       }, 100);
    

    【讨论】:

      猜你喜欢
      • 2015-06-16
      • 2019-06-02
      • 1970-01-01
      • 1970-01-01
      • 2014-09-04
      • 2011-03-14
      • 2013-07-17
      • 2017-08-22
      相关资源
      最近更新 更多