我与 animate.css 一起工作.我有一个这样的 html:
index.html
<h1>Example</h1><div class="instagram-widget"></div>
index.js
jQuery('h1').mouseenter(function () {
jQuery(this).addClass('fadeInUp').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
jQuery(this).addClass('fadeOutUp').removeClass('fadeInUp').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
jQuery(this).removeClass('fadeOutUp');
});
}); });
一切正常!
我有一个带 API 的 Instagram(我可以显示我的照片 - 不用担心 API)。我将 API 代码添加到 index.js。我没有将所有代码放在这里是为了简化问题。我追加
jQuery('<a>').attr('href', url).append( // inside it, append an image
jQuery('<img>').attr('src',src),
jQuery('<div class="comment">').html(comment) ) // end append
.appendTo('.instagram-widget')
然后我改变jQuery('h1').mouseenter(function () {
至 jQuery('.comment').mouseenter(function () {
努力工作。看起来像因为 .comment
与 jQuery('.comment').mouseenter(function () {
同时执行因为在一个文件中。
问题
如何制作.comment
作品?是否有任何函数可以在另一个脚本完全完成后加载一个脚本?
最佳答案
你可以使用 Promise为此 - 好的方法,或者只是 .setTimeout()
- 不好的方法。
使用 Promise,您可以确保一段代码只会在另一段之后执行。
关于javascript - 在 jQuery 中的另一个脚本之后运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37364863/