[返回]
中国计算机报2000年第88期用javascript制作鼠标感应效果
小 晓
html是一种功能强大的描述型语言,用它可以制作的网页可以包含图片、声音、甚至视频等多媒体效果。恰当地把java或javascript语言结合起来还能设计出一些更为特殊的效果。今天我们就用javascript制作鼠标感应的效果:鼠标会自动放大缩小图片的链接!
第一步,将下面的代码加入〈head〉〈/head〉之间:
〈script language='javascript1.2'〉
function expand() {
if (smallslot.width〈=102) {
x=window.settimeout('expand()', 10)
smallslot.width=smallslot.width + 5
smallslot.height=smallslot.height + 5
}
else {
settimeout('reduce()', 0)
}
}
function reduce() {
if (smallslot.width〉80) {
x=window.settimeout('reduce()', 10)
smallslot.width=smallslot.width - 5
smallslot.height=smallslot.height - 5
}
}
〈/script〉
第二步:将下面的原代码加入〈body〉〈/body〉之间:
〈div id='slot1' onmouseover='expand()' style='height: 102px; width: 80px'〉〈ahref='http://netschool.myweb.com.cn/' target='_top'〉
〈dd〉〈img border='0' hspace='0' id='smallslot' src='ajie.gif' style='left: 296px; position: absolute; top: 104px; visibility: visible; z: 2' width='80' height='102'〉〈/a〉 〈/dd〉
〈/div〉