简体   繁体   English

我的jQuery代码不适用于WebStorm,但适用于CodePen

[英]My jQuery code isn't working with WebStorm, but it is working with CodePen

I'm trying to make it so when I click a button it autoscrolls down using jQuery. 我试图做到这一点,所以当我单击一个按钮时,它将使用jQuery自动向下滚动。 It would look a lot better than a regular html jump. 它看起来比常规的html跳转要好得多。 However, the code is only working on my CodePen/its exports, but not from anything through my WebStorm. 但是,该代码仅适用于我的CodePen /它的导出,而不能通过WebStorm进行任何操作。

I've made sure to add the library for jQuery and added the script call. 我已经确保添加了jQuery库并添加了脚本调用。 I know the library is added because it doesn't show squiggly's under the $ anymore, but the code still isn't functioning correctly. 我知道添加了该库是因为它不再显示$下方的弯曲,但是代码仍然无法正常运行。 The script call is there -- definitely, because it works with CodePen using the exact same (copied and pasted) code. 脚本调用在那里-肯定是,因为它使用完全相同(复制和粘贴)的代码与CodePen一起使用。

HTML: HTML:

 <script src="http://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"> </script> <script> src="js/main.js>" </script> 

JS: JS:

 //Animate Smooth Scroll $('#view-work').on('click',function() { const images = $('#images').position().top; $('html, body').animate({ scrollTop: images }, 900 ); }); 

Full: https://codepen.io/at-lowdesu/pen/LKJKLr 完整: https : //codepen.io/at-lowdesu/pen/LKJKLr

I'm expecting it autoscroll like it does on CodePen, but through my WebStorm IDE and its exports. 我希望它像在CodePen上一样自动滚动,但是要通过我的WebStorm IDE及其导出。

Solved. 解决了。 I wasn't using the script call correctly. 我没有正确使用脚本调用。 <script> src="js/main.js>" </script> should be <script src="js/main.js"> </script> <script> src="js/main.js>" </script>应该是<script src="js/main.js"> </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM