jquery实现鼠标经过图片时,图片上下跳动

<ul id="ul">
    <li><img src="images/01.jpg"/></li>
    <li><img src="images/02.jpg"/></li>
</ul>
<script type="text/javascript">
    $(function(){
	    $("#ul img").each(function(k,img){
		    new JumpObj(img,10);
	    });
    });
</script>
<script type="text/javascript">
    function JumpObj(elem, range, startFunc, endFunc) {
	    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;
    }
</script>

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值