javascript 我想在另一个月份移入时,下面的内容先变为0px; 然后在执行 starMove (60); 该怎么做呢?

沫叶小生 沫叶小生 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
<!DOCTYPE html>
<html>
<head>
<title>显示周几</title>
<meta charset="utf-8" />
<style type="text/css">
*{
margin: 0;padding: 0;
}
body{
font-size: 0;
font-family: myFont;
}
@font-face{
font-family: myFont;
src: url(../font/MyriadPro-Light.otf);
}

.container{
width: 300px;height: 300px;
margin: 40px auto;
background: #eaeaea;
font-size: 14px;
padding-bottom: 20px;
overflow: hidden;
position: relative;
}
.container ul{
list-style: none;
overflow: hidden;
}
.container li{
text-align: center;
width: 50px;height: 50px;
margin: 20px 0 0 20px;
background: #424242;
color: #fff;
float: left;
cursor: crosshair;
}
.container li strong{
font-weight: 600;
display: block;
font-size: 18px;
margin-top: 4px;
}
.container li.active{
background: #fff;
color: #f90;
}

.content_div{
width: 254px;height: 60px;
background: #f1f1f1;
color: #0099FF;
position: absolute;
left: 20px;top: 230px;
}
</style>
<script type="text/javascript">

function $ (id)
{
return typeof id === "string" ? document.getElementById(id) : id;
};

window.onload = function ()
{
// 获取元素
var aLi = $ ("title_menu").getElementsByTagName("li");
var oContent = $ ("content_div");
var oStrong = oContent.getElementsByTagName("strong")[0];
var oP = oContent.getElementsByTagName("p")[0];

// 节日数组
var aHoliday =
[
"元旦:1月1日至3日放假三天。",
"春节:2月2日至8日放假7天。",
"妇女节:3月8日妇女节,与我无关。",
"清明节:4月3日至5日放假3天",
"劳动节:4月30日至5月2日放假3天。",
"端午节:6月4日至6日放假3天。",
"小暑:7月7日小暑。不放假。",
"七夕节:8月6日七夕节。不放假。",
"中秋节:9月10日至12日放假3天。",
"国庆节:10月1日至7日放假7天。",
"立冬:11月8日立冬。不放假。",
"艾滋病日:12月1日; 废除奴隶制国际日:12月2日。"
];

// 遍历 aLi
for (var i = 0; i < aLi.length; i++)
{
aLi[i].index = i; // 设置下标

// 鼠标经过事件
aLi[i].onmouseover = function ()
{
// 运动并显示
starMove (60);
// oContent.style.display = "block";

for (var j = 0; j < aLi.length; j ++)
{
aLi[j].className = ""; // 清除所有 class
}

this.className = "active"; // 设置 class

oStrong.innerHTML = this.index + 1;
oP.innerHTML = aHoliday[this.index];
};

aLi[i].onmouseout = function ()
{
// 运动并隐藏
starMove (0);
// oContent.style.display = "none";
};
}
};


var timer = null; // 定时器

// 运动函数
function starMove (iTarget)
{
var oContent = $ ("content_div"); // 获取元素

clearInterval(timer);
timer = setInterval(function ()
{
// 速度及取整
var iSpeed = (iTarget - oContent.offsetHeight) / 4;
iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);

if (iTarget == oContent.offsetHeight)
{
clearInterval(timer);
}else
{
oContent.style.height = oContent.offsetHeight + iSpeed + "px";
}
},30);
};



</script>
</head>
<body>
<div class="container">
<ul id="title_menu">
<li>
<strong>1</strong>
Jan.
</li>
<li>
<strong>2</strong>
Feb.
</li>
<li>
<strong>3</strong>
Mar.
</li>
<li>
<strong>4</strong>
Apr.
</li>
<li>
<strong>5</strong>
May.
</li>
<li>
<strong>6</strong>
Jun.
</li>
<li class="active">
<strong>7</strong>
Jul.
</li>
<li>
<strong>8</strong>
Aug.
</li>
<li>
<strong>9</strong>
Sep.
</li>
<li>
<strong>10</strong>
Oct.
</li>
<li>
<strong>11</strong>
Nov.
</li>
<li>
<strong>12</strong>
Dec.
</li>
</ul>
<div id="content_div" class="content_div">
<h3>
<strong>7</strong>
月节日 :
</h3>
<p>小暑:7月7日小暑。不放假。</p>
</div>
</div>

</body>
</html>
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
沫叶小生
JavaScript 87,983 成员 224,681 内容