0731-84469346 / 152-7483-9229
更新时间:2015年10月21日

鼠标放上去 图片上下移动代码

<html>
<STYLE type=text/css>
<!--
a:hover{ border:#09F 1px dashed;}
image{border:none}
-->
</STYLE>

<body>
<div>
<div><a href="#"><img id="imgtest" src="http://news.idcquan.com/UploadFiles_9551/200901/20090107110821572.jpg" /></a></div>
</div>
</body>
<script>
function JumpObj(elem, range, startFunc, endFunc) {
//图片鼠标移上去的动画效果,感谢aoao的支持
var curMax = range = range || 6;
startFunc = startFunc || function(){};
endFunc = endFunc || function(){};
var drct = 0;
var step = 1;

init();

function init() { elem.style.position = 'relative';active() }
function active() { elem.onmouseover = function(e) {if(!drct)jump()} }
function deactive() { elem.onmouseover = null }

function jump() {
var t = parseInt(elem.style.top);
if (!drct) motionStart();
else {
var nextTop = t - step * drct;
if (nextTop >= -curMax && nextTop <= 0) elem.style.top = nextTop + 'px';
else if(nextTop < -curMax) drct = -1;
else {
var nextMax = curMax / 2;
if (nextMax < 1) {motionOver();return;}
curMax = nextMax;
drct = 1;
}
}
setTimeout(function(){jump()}, 200 / (curMax+3) + drct * 3);
}
function motionStart() {
startFunc.apply(this);
elem.style.top='0';
drct = 1;
}
function motionOver() {
endFunc.apply(this);
curMax = range;
drct = 0;
elem.style.top = '0';
}

this.jump = jump;
this.active = active;
this.deactive = deactive;
}
new JumpObj(document.getElementById("imgtest"),10)
</script>
</html>


上一篇: 国内国外优秀素材网站大全及实用网址
下一篇:用javascript实现的最简单留言本无数据库