HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle1.css">
<title>hd images</title>
</head>
<body>
<div id="top1">
<div class="inside1">
<div class="nested_inside1"> MY HAPPY PLACES </div>
</div>
<div class="inside2">
<div class="nested_inside2"> CLUMSSY BEACHES
</div>
</div>
<div class="inside3">
<div class="nested_inside3"> REGULAR APPLES </div>
</div>
<div class="inside4">
<div class="nested_inside4"> LUSTY BRUSHES </div>
</div>
<div class="inside5">
<div class="nested_inside5"> ECSTATIC DIMENSIONS </div>
</div>
<div class="inside6">
<div class="nested_inside6"> CURLY HILLS </div>
</div>
<div class="inside7">
<div class="nested_inside7"> SHINY WATER </div>
</div>
<div class="inside8">
<div class="nested_inside8"> COOL BOATS </div>
</div>
<div class="inside9">
<div class="nested_inside9"> CRUNCHY CLUSHTERS </div>
</div>
<script type="text/javascript" src="myscript2.js"></script>
</body>
</html>
的JavaScript
$(document).ready(function() {
$("#top1").on("hover", ".nested_inside", function() {
$(this).animate({
"top": "-10px"
});
});
});
答案 0 :(得分:0)
这不起作用,因为你没有班级nested_inside
但是nested_inside1
,ensted_inside2
......等等......你必须删除这些数字
为每一个人改编它:
<div class="inside7">
<div class="nested_inside"> SHINY WATER </div>
</div>
你还需要在脑中包含jquery:
<script src="path/to/jquery.js"></script>
像这样修改你的代码:
$(document).ready(function() {
$("#top1").on("mouseover", ".nested_inside", function() {
$(this).animate({
"top": "-10px"
});
});
});
和你的CSS一样:
.nested_inside {
position: relative;
}
答案 1 :(得分:0)
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js">
</script>
<script type="text/javascript" src="myscript2.js"></script>
<link rel="stylesheet" type="text/css" href="mystyle1.css">
<title>hd images</title>
</head>
您需要在<head>
中添加指向jquery文件的链接,然后再添加您的jquery文件。
答案 2 :(得分:0)
这有两个固有的问题:
.nested_inside
以确保top
属性有效mouseenter
和mouseleave
并执行必要的动画我根据我应该如何运作的假设添加了一个小提琴: https://jsfiddle.net/fxmtz2yn/
$(document).ready(function() {
$("#top1").on("mouseover mouseleave", ".nested_inside",function(evt) {
var $el = $(this),
top = $el;
switch(evt.type) {
case "mouseover":
$el.animate({
"top": "-10px"
});
break;
case "mouseleave":
$el.animate({
"top": "0"
});
break;
}
});
});
答案 3 :(得分:0)
\e
hover()需要回调