仿谷歌主頁js動(dòng)畫效果實(shí)現(xiàn)代碼
更新時(shí)間:2013年07月14日 15:25:11 作者:
昨天看到谷歌的主頁上出現(xiàn)了幾個(gè)動(dòng)畫,發(fā)現(xiàn)不是flash做的,而是用js+圖片實(shí)現(xiàn)的!今天把拷貝到的圖片,用js實(shí)現(xiàn)了動(dòng)畫效果!
源代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>谷歌主頁動(dòng)畫</title>
<style type="text/css">
.animate{
height:156px;
width:97px;
background:url(images/gumby11-gumby.jpg) no-repeat;
background-position:-15581px center;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var offset = -15678;
$('#start').click(function(){
var timer = setInterval(function(){
offset += 98;
$('#animate').css({
'background-position':offset + 'px center'
});
if(offset > 0){
clearInterval(timer);
}
},50);
$(this).hide();
});
});
</script>
</head>
<body>
<div id="animate" class="animate"></div>
<a id="start" href="javascript:void(0)">動(dòng)起來吧!</a>
</body>
</html>
其實(shí)這動(dòng)畫不難,難在那種圖片上,不知道這圖片是怎么做出來的?。?!
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>谷歌主頁動(dòng)畫</title>
<style type="text/css">
.animate{
height:156px;
width:97px;
background:url(images/gumby11-gumby.jpg) no-repeat;
background-position:-15581px center;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var offset = -15678;
$('#start').click(function(){
var timer = setInterval(function(){
offset += 98;
$('#animate').css({
'background-position':offset + 'px center'
});
if(offset > 0){
clearInterval(timer);
}
},50);
$(this).hide();
});
});
</script>
</head>
<body>
<div id="animate" class="animate"></div>
<a id="start" href="javascript:void(0)">動(dòng)起來吧!</a>
</body>
</html>
其實(shí)這動(dòng)畫不難,難在那種圖片上,不知道這圖片是怎么做出來的?。?!
相關(guān)文章
JS實(shí)現(xiàn)注冊(cè)界面表單校驗(yàn)
這篇文章主要為大家詳細(xì)介紹了JS實(shí)現(xiàn)注冊(cè)界面表單校驗(yàn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08
D3.js實(shí)現(xiàn)餅圖,環(huán)圖,玫瑰圖的繪制
這篇文章主要為大家介紹了如何利用D3.js中的d3.pie和d3.arc實(shí)現(xiàn)餅圖、環(huán)圖和玫瑰圖的繪制,文中的實(shí)現(xiàn)方法講解詳細(xì),感興趣的可以嘗試一下2022-11-11
用javascript做一個(gè)webgame連連看大家看下
2008-01-01
JavaScript實(shí)現(xiàn)密碼框驗(yàn)證信息
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)密碼框驗(yàn)證信息,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11
Google (Local) Search API的簡(jiǎn)單使用介紹
這篇文章主要介紹了Google (Local) Search API的簡(jiǎn)單使用。需要的朋友可以過來參考下,希望對(duì)大家有所幫助2013-11-11
JavaScript字符串操作的四個(gè)實(shí)用技巧
在制作前端頁面的過程中,經(jīng)常需要用到JavaScript進(jìn)行邏輯處理,很多時(shí)候都需要對(duì)字符串進(jìn)行操作,這篇文章主要給大家介紹了關(guān)于JavaScript字符串操作的四個(gè)實(shí)用技巧,需要的朋友可以參考下2021-07-07

