当前位置 - 股票行情交易網 - 文娛動態 - jquery計時器

jquery計時器

<!DOCTYPE?html>

<html?lang="en">

<head>

<meta?charset="UTF-8">

<title>Document</title>

<style>

*{margin:0;padding:0;}

.demo{width:269px;height:300px;margin:100px?auto;cursor:pointer;}

</style>

</head>

<body>

<div?class="demo">

<img?src="pic.jpg"?/>

</div>

<script?src="jquery-1.10.1.js"></script>

<script>

$(function(){

var?t=3000;//這裏設定消失的時間是3秒;

function?funA(){//這個函數是起消失作用的函數,會讓圖片元素消失;

$(".demo?img").fadeOut();

}

var?doA=setTimeout(funA,t);//這裏是默認情況下的執行消失函數;

function?stopfunA(){//這裏是禁止圖片元素消失的函數

clearTimeout(doA)

}

$(".demo?img").hover(function(){//圖片元素獲得焦點後

stopfunA();?//清除了消失函數,所以圖片元素會壹直存在

})

})

</script>

</body>

</html>