Ramjet:如何使元素出现并重新出现

时间:2015-05-07 13:13:55

标签: javascript jquery html css

所以我正在尝试遵循ramjet http://www.rich-harris.co.uk/ramjet/的代码,但是在进入b时我无法获得元素a消失。我也得到了--Uncaught TypeError:无法读取undefined--的属性'add'。但是元素a确实会移动。如何转到b,如页面所示。​​

的script.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>

stylesheet.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;
}

2 个答案:

答案 0 :(得分:1)

这是我头标记中的脚本:

<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得到了b的属性。

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

答案 1 :(得分:1)

that's my div ' a '

在更改我的div之前

看起来像这样。在DOM获取加载后,它将转为并获取div b的属性为红色: after DOM load