【发布时间】:2020-09-09 04:55:42
【问题描述】:
我是 JQuery 的新手,想知道如何引用 google 的 CDN 以使我的 JQuery 文件能够正常工作。我的脚本没有运行,因为它不会引用 JQuery CDN。我在下面要做的就是在将鼠标悬停在图像上时调整图像的大小。这真的不应该太难,但我不知道如何引用 JQuery CDN。任何帮助深表感谢。谢谢!
<!DOCTYPE html>
<html>
<head>
<title>Image Resize</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
var ht = $("img").height(),
wd = $("img").width(),
mult = 1.5;
$("img").on('mouseenter', function () {
$(this).animate({
height: ht * mult,
width: wd * mult
}, 500);
});
$("img").on('mouseleave', function () {
$(this).animate({
height: ht,
width: wd
}, 500);
})
</script>
</head>
<body>
<img src="https://cdn1.iconfinder.com/data/icons/yooicons_set01_socialbookmarks/512/social_google_box.png" width="200" height="200" border="5" alt="" style="border-color:red" />
</body>
</html>
【问题讨论】:
-
您已经很好地引用了 CDN - 问题是因为您的代码不在 document.ready 事件处理程序中 -
$(function() { /* your JS code here */ }); -
所以我只是在我的函数之前插入它?然后将我的函数放入其中并用 将其全部关闭?
-
你们是最棒的,只是想通了。很抱歉成为这样的菜鸟。我真的在努力学习。太感谢了! @RoryMcCrossan 和 dsg