簡體   English   中英

Ramjet:如何使元素出現並重新出現

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

因此,我嘗試遵循ramjet的代碼http://www.rich-harris.co.uk/ramjet/ ,但是我無法使元素a移入b時消失。 我還收到--Uncaught TypeError:無法讀取未定義的屬性'add'-。 不過,元素a確實會移動。 如頁面所示,如何使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;
}

這是我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的屬性。

我認為問題出在您在文檔標題部分定義的腳本路徑中。 檢查您的路徑。

那是我的div'a'

在更改我的div之前,看起來像這樣。 在DOM獲得負載之后,它將旋轉並獲取div b的屬性為紅色: DOM加載后

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM