【发布时间】:2021-10-24 04:51:07
【问题描述】:
我想要的是,当在行中单击时会生成过渡.. 不仅是第一次单击。我试过了,但它不起作用...问题是它只在第一次点击时转换,我不希望那样。
这是我的代码:
let table = document.querySelectorAll(".table-row");
let derDiv = document.querySelector(".der");
let derInfoDiv = document.querySelector(".der .info");
let cont = 0;
table.forEach(tr => {
tr.addEventListener('click', () => {
if (cont > 0) {
// doesn't work
derDiv.classList.add('auxClas');
derInfoDiv.children[0].remove();
derDiv.children[1].remove();
console.log(derDiv.style.top)
console.log(derDiv.style.display);
}
cont++;
let title = tr.children[0].textContent;
let imgSrc = tr.children[1].children[0].src;
const img = document.createElement("img");
img.src = imgSrc;
const h3 = document.createElement("h3");
h3.textContent = title;
derDiv.appendChild(h3);
derInfoDiv.appendChild(img);
derDiv.style.top = 0;
})
});
#container {
width: 80%;
display: flex;
margin: 0 auto;
justify-content: space-between;
}
.izq {
flex-basis: 40%;
}
.der {
flex-basis: 40%;
display: flex;
flex-direction: column;
position: relative;
top: -400px;
transition: top 1s;
}
.info {
flex-basis: 30%;
}
.info img {
width: 100%;
}
.auxClas {
flex-basis: 40%;
display: flex;
flex-direction: column;
position: relative;
top: -400px;
transition: top 1s;
}
<div id="container">
<!-- left -->
<div class="izq">
<table style="width:100%">
<tr>
<th>Product Name</th>
<th>Image</th>
</tr>
<tr class="table-row">
<td>Acoustic guitar</td>
<td>
<img style="display:none;"
src="https://cdn-5bf30923f911c819844cc261.closte.com/wp-content/uploads/2018/05/Guitarra-Acustica-Cort-AD810.jpg">
</td>
</tr>
<tr class="table-row">
<td>Keyboard..</td>
<td>
<img style="display:none;" src="https://m.media-amazon.com/images/I/611i09m4QUL._AC_SX679_.jpg">
</td>
</tr>
</table>
</div>
<!-- right -->
<div class="der">
<div class="info">
</div>
</div>
</div>
我尝试更新值“top”,因为第二次单击后该值仍为 0。但是,不起作用。请你帮帮我。
【问题讨论】:
标签: javascript html css css-transitions