简体   繁体   English

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

[英]Ramjet: How to make element appear and reappear

So I'm trying to follow the code for ramjet http://www.rich-harris.co.uk/ramjet/ , but I can't get element a to disappear while moving into b. 因此,我尝试遵循ramjet的代码http://www.rich-harris.co.uk/ramjet/ ,但是我无法使元素a移入b时消失。 I also get --Uncaught TypeError: Cannot read property 'add' of undefined--. 我还收到--Uncaught TypeError:无法读取未定义的属性'add'-。 Element a does move, though. 不过,元素a确实会移动。 How can I get a to turn into b, as shown on the page. 如页面所示,如何使a变成b。

Script.js 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 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 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;
}

here is the script in my head tag: 这是我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>

no change in css the code works fine. CSS中没有任何更改,代码工作正常。 the div b got hide and div a acquire the property of b. div b获得了hide并div a获得了b的属性。

i think the problem is in your script path the you define in your docs head section. 我认为问题出在您在文档标题部分定义的脚本路径中。 check your path. 检查您的路径。

那是我的div'a'

before changing my div a looks like this. 在更改我的div之前,看起来像这样。 after the DOM get loads it turns and acquire the property of div b as red: 在DOM获得负载之后,它将旋转并获取div b的属性为红色: DOM加载后

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM