gpt4 book ai didi

javascript - 冲压发动机 : How to make element appear and reappear

转载 作者:太空宇宙 更新时间:2023-11-04 03:07:57 25 4
gpt4 key购买 nike

所以我正在尝试遵循冲压喷气发动机的代码 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 的属性。

我认为问题出在您在文档头部部分定义的脚本路径中。检查你的路径。

关于javascript - 冲压发动机 : How to make element appear and reappear,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30102156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com