为什么会发生此JQuery错误?动画不是功能 [英] Why is this JQuery error happening? Animate is not a function

查看:90
本文介绍了为什么会发生此JQuery错误?动画不是功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习jQuery,并尝试解决滚动效果问题.无论如何,我正在尝试使此代码正常工作,但是这样做很麻烦.运行动画功能时会中断:

I am learning jQuery and trying to work my way around a scroll effect. Anyway, I am trying to make this code work but having trouble in doing so. It breaks when It runs the animate function:

非常感谢您在此方面的帮助.谢谢.

I would really appreciate your help on this one. Thank you.

未捕获的TypeError:$(...).animate不是函数
在HTMLAnchorElement. (script.js:58)
在HTMLDocument.dispatch(jquery-3.1.1.slim.min.js:3)
在HTMLDocument.q.handle(jquery-3.1.1.slim.min.js:3)

Uncaught TypeError: $(...).animate is not a function
at HTMLAnchorElement. (script.js:58)
at HTMLDocument.dispatch (jquery-3.1.1.slim.min.js:3)
at HTMLDocument.q.handle (jquery-3.1.1.slim.min.js:3)

// Select anchor tags to click on 
$(document).on("click", "a", function(event) {
  console.log("item clicked");

  // Clear out the default action  
  event.preventDefault();
  console.log("working until now");

  // Animate to selected selected target
  $("html,body").animate({
    scroll: $($(this).attr('href')).offset().top
  }, 900);
  console.log("no errors for now");
});

<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<script src="javascript/script.js">
</script>

推荐答案

这是因为您使用的是jQuery版本. https://code.jquery.com/jquery-3.1.1.slim.min.js

It's because of the jQuery version you use. https://code.jquery.com/jquery-3.1.1.slim.min.js

slim版本的jQuery不包含所有原始jQuery函数.

slim version of jQuery does not contain all the original jQuery functions.

您应该使用full版本.您可以从 此处 下载.

You should use a full version. You can download it from here.

如果您阅读以下文章,将有助于更好地理解 此处 在其中的某个位置上,您会找到此语句,然后我引用:

It will help to better understand if you read this article from here where at some point in it you will find this statement and I quote:

苗条的身材

Slim build

最后,我们在此版本中添加了一些新内容.有时候你 不需要ajax,或者您更喜欢使用众多独立版本之一 专注于ajax请求的库.而且通常更容易使用 CSS和类操作的组合,适用于您的所有Web 动画.以及jQuery的常规版本,其中包括 ajax和效果模块,我们发布了一个苗条"版本, 不包括这些模块.总而言之,它不包括Ajax,效果和 当前不推荐使用的代码.

Finally, we’ve added something new to this release. Sometimes you don’t need ajax, or you prefer to use one of the many standalone libraries that focus on ajax requests. And often it is simpler to use a combination of CSS and class manipulation for all your web animations. Along with the regular version of jQuery that includes the ajax and effects modules, we’re releasing a "slim" version that excludes these modules. All in all, it excludes ajax, effects, and currently deprecated code.

这篇关于为什么会发生此JQuery错误?动画不是功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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