Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Scrollspy不适用于ios设备_Javascript_Jquery_Html_Ios_Css - Fatal编程技术网

Javascript Scrollspy不适用于ios设备

Javascript Scrollspy不适用于ios设备,javascript,jquery,html,ios,css,Javascript,Jquery,Html,Ios,Css,我刚刚完成了我的第一个网站,它是我的投资组合网站。无论如何,在我的导航栏上,我有我的链接可以滚动到页面上的某个部分。它在桌面和我的安卓设备(lg g4、nexus 7)上都能完美工作 但当我试图在我妻子的iphone上使用它时(也在iPodtouch上试用过),它根本不起作用。我也尝试在ios上使用chrome而不是safari,这也是同样的问题。(ios的另一个问题是,主页图像只显示最顶端(云层),这也很奇怪,同样只出现在ios上) 下面是我正在使用的javascript代码,但我也尝试过使用

我刚刚完成了我的第一个网站,它是我的投资组合网站。无论如何,在我的导航栏上,我有我的链接可以滚动到页面上的某个部分。它在桌面和我的安卓设备(lg g4、nexus 7)上都能完美工作

但当我试图在我妻子的iphone上使用它时(也在iPodtouch上试用过),它根本不起作用。我也尝试在ios上使用chrome而不是safari,这也是同样的问题。(ios的另一个问题是,主页图像只显示最顶端(云层),这也很奇怪,同样只出现在ios上)

下面是我正在使用的javascript代码,但我也尝试过使用smoothScroll(去掉js脚本),这也不起作用。js将在下面,我的代码笔也将对你来说太难测试了。任何帮助都将不胜感激,谢谢


$(文档).ready(函数(){
$('body').scrollspy({
目标:“.navbar”,
抵销:50
});
//将平滑滚动添加到导航栏内的所有链接
$(“#myNavbar a”)。在('click',函数(事件){
//防止默认锚点单击行为
event.preventDefault();
//存储哈希(#)
var hash=this.hash;
//使用jQuery的animate()方法添加平滑页面滚动
//可选数字(800)指定滚动到指定区域所需的毫秒数(动画的速度)
$('html,body')。设置动画({
scrollTop:$(散列).offset().top
},800,函数(){
//完成滚动后,将哈希(#)添加到URL(默认单击行为)
window.location.hash=散列;
});
});
});
    <script async>
    $(document).ready(function(){
        $('body').scrollspy({
  target: ".navbar",
  offset: 50
});

// Add smooth scrolling to all links inside a navbar
$("#myNavbar a").on('click', function(event) {

  // Prevent default anchor click behavior
  event.preventDefault();

  // Store hash (#)
  var hash = this.hash;

  // Using jQuery's animate() method to add smooth page scroll
  // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area (the speed of the animation)
  $('html, body').animate({
    scrollTop: $(hash).offset().top
  }, 800, function() {

    // Add hash (#) to URL when done scrolling (default click behavior)
    window.location.hash = hash;
  });
});
});

    </script>