jQuery scrollTo 不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16345626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:58:21  来源:igfitidea点击:

scrollTo is not a function

jqueryfunctionscrollto

提问by Luc

Ok, I can't see it anymore. I'm using the scrollTo pluginand have a scrollTo function in my website. It worked and now suddenly it doesn't...

好吧,我再也看不到了。我正在使用scrollTo 插件并在我的网站中有一个 scrollTo 功能。它起作用了,现在突然没有了......

This is my code:

这是我的代码:

$(document).ready(function() {
    $('header').delay(300).fadeIn(750);
    $('#intro_text').delay(800).fadeIn(750);
    $("#jquery_jplayer_1").jPlayer({
        ready: function () {
            $(this).jPlayer("setMedia", {
                m4v: "mi4.m4v",
                ogv: "mi4.ogv",
                webmv: "mi4.webm",
                poster: "mi4.png"
            });
        },
        swfPath: "js",
        supplied: "webmv, ogv, m4v",
        size: {
            width: "570px",
            height: "340px",
            cssClass: "jp-video-360p"
        }
    });
});

$(function(toDemos) {
 $('h1').click(function() {
        $.scrollTo('#intro', 800);
    });
});

$(function(toDemos) {
 $('#contact').click(function() {
        $.scrollTo('footer', 800);
    });
});

$(function(toDemos) {
 $('#demos').click(function() {
        $.scrollTo('#content', 800);
    });
});

$(function(toDemos) {
 $('#toTop').click(function() {
        $.scrollTo('#intro', 800);
    });
});

$(function() {
    $("#playlist li").on("click", function() {
        $("#videoarea").attr({
            "src": $(this).attr("movieurl"),
            "poster": "",
            "autoplay": "autoplay"
        })
    })
    $("#videoarea").attr({
        "src": $("#playlist li").eq(0).attr("movieurl"),
        "poster": $("#playlist li").eq(0).attr("moviesposter")
    })
})

I'm just a beginner at this, but I don't think I did much wrong. Is there anything wrong here? I can't see it.

我只是这方面的初学者,但我不认为我做错了什么。这里有什么问题吗?我看不到。

Hopefully one of you can! Much thanks in advance.

希望你们中的一个可以!非常感谢提前。

回答by Brian Phillips

If you're using flesler's scrollTo plugin, you may need to modify the duration option:

如果您使用flesler 的 scrollTo 插件,您可能需要修改持续时间选项:

$.scrollTo('footer', { duration:800 });

Download the plugin source hereif you haven't already. I would verify that it is correctly linked to your code. Also try a debugging tool like firebugto help with the troubleshooting.

如果您还没有,请在此处下载插件源。我会验证它是否正确链接到您的代码。还可以尝试使用诸如firebug 之类的调试工具来帮助进行故障排除。

NOTE:

笔记:

To point out Mark'sanswer in the comments below for anyone who stumbles on this, jQuery must be linked first in order in the file before any plugins are loaded. E.g.:

为了在下面的评论中为任何偶然发现此问题的人指出Mark 的回答,在加载任何插件之前,必须首先在文件中按顺序链接 jQuery。例如:

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.scrollTo.min.js"></script>

回答by Daut

This is quite old question but I thought I would share my way :)

这是一个很老的问题,但我想我会分享我的方式:)

$("button").on('click', function() {
 window.scrollTo({
    top: $('#intro').offset().top,
    left: 0,
    behavior: 'smooth'
  })
});
.wrapper {

  height:1000px;
  width: 300px;
  background: #eee;
}

.other {
  height: 500px;
  background: #ddd;
  padding: 20px;
  width: 100%;
}

#intro {
  height: 500px;
  background: #bbb;
  padding: 20px;
  width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Click</button>
<div class="wrapper">
  <div class="other">Other div</div>
  <div id="intro">
    Intro
  </div>
</div>

回答by MD. Nazim

$("button").on('click', function() {
 window.scrollTo({
    top: $('#intro').offset().top,
    left: 0,
    behavior: 'smooth'
  })
});
.wrapper {

  height:1000px;
  width: 300px;
  background: #eee;
}

.other {
  height: 500px;
  background: #ddd;
  padding: 20px;
  width: 100%;
}

#intro {
  height: 500px;
  background: #bbb;
  padding: 20px;
  width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Click</button>
<div class="wrapper">
  <div class="other">Other div</div>
  <div id="intro">
    Intro
  </div>
</div>