0
我想创建一个'onclick'函数。 这就是我在Youtube的帮助下所能做的。 现在我想添加一个函数,当我点击灰色字段时,另一个容器以50%的宽度向右移动。我想用文字和图片填写这个div。 对不起我的英文不好,我希望你们明白我想如何创建'onclick'功能?
.news {
position: fixed;
display: block;
width: 33.33%;
height: 100%;
float: left;
background-color: grey;;
background-size: auto, cover;
transition: width 0.5s;
}
.open{
width: 50%;
transition: width 0.5s;
position: fixed;
display: block;
width: 50%;
height: 100%;
float: left;
background-color: grey;
background-size: auto, cover;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/style.css">
<script>
function toggleClass (el) {
if(el.className == "news"){
\t \t el.className = "open";
\t } else {
\t \t el.className = "news";
\t }
}
</script>
</head>
<body>
<div class="news" onclick="toggleClass(this)"></div>
</body>
</html>
动听的名字的人的东西。 –
努力工作,鼻子上一本好书。 – Teemu