所以我正在尝试遵循冲压喷气发动机的代码 http://www.rich-harris.co.uk/ramjet/ ,但我无法让元素 a 在移动到 b 时消失。我还得到 --Uncaught TypeError: Cannot read property 'add' of undefined--。不过,元素 a 确实会移动。如何让 a 变成 b,如页面所示。
脚本.js
$(document).ready( function() {
// set the stage so ramjet copies the right styles...
b.classList.remove('hidden');
ramjet.transform( a, b, {
done: function () {
// this function is called as soon as the transition completes
b.classList.remove('hidden');
}
});
// ...then hide the original elements for the duration of the transition
a.classList.add('hidden');
b.classList.add('hidden');
});
index.html
<!DOCTYPE HTML>
<html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet.css" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="./ramjet.js"></script>
<script type="text/javascript" src="./script.js"></script>
</head>
<body>
<div class="back">
<div id="a"></div>
<div id="b" class="hidden"></div>
</div>
</body>
</html>
样式表.css
.back {
float: left;
width: 790px;
height: 525px;
border-radius: 5px;
background-color: #BCD2EE
}
#a {
margin: 200px 10px;
margin-right: auto;
width: 175px;
height: 60px;
background-color: #666699;
display: inline-block;
position: relative;
border: 2px solid black;
}
#b {
margin: 200px 10px;
margin-right: auto;
width: 175px;
height: 60px;
background-color: red;
display: inline-block;
position: relative;
border: 2px solid black;
}
.hidden {
visibility: hidden;
}
这是我的 head 标签中的脚本:
<script type="text/javascript" src="jquery-1.11.1.js"></script>
<script type="text/javascript" src="ramjet.js"></script>
<script type="text/javascript">
$(document).ready( function() {
// set the stage so ramjet copies the right styles...
b.classList.remove('hidden');
ramjet.transform( a, b, {
done: function () {
// this function is called as soon as the transition completes
b.classList.remove('hidden');
}
});
// ...then hide the original elements for the duration of the transition
a.classList.add('hidden');
b.classList.add('hidden');
});
</script>
CSS没有变化代码工作正常。 div b 得到了 hide,div a 获得了 b 的属性。
我认为问题出在您在文档头部部分定义的脚本路径中。检查你的路径。
我是一名优秀的程序员,十分优秀!