仿谷歌主頁js動畫效果實現(xiàn)代碼
更新時間:2013年07月14日 15:25:11 作者:
昨天看到谷歌的主頁上出現(xiàn)了幾個動畫,發(fā)現(xiàn)不是flash做的,而是用js+圖片實現(xiàn)的!今天把拷貝到的圖片,用js實現(xiàn)了動畫效果!
源代碼:
<!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>谷歌主頁動畫</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)">動起來吧!</a>
</body>
</html>
其實這動畫不難,難在那種圖片上,不知道這圖片是怎么做出來的!??!
復(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>谷歌主頁動畫</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)">動起來吧!</a>
</body>
</html>
其實這動畫不難,難在那種圖片上,不知道這圖片是怎么做出來的!??!
相關(guān)文章
JavaScript一文帶你玩轉(zhuǎn)web表單網(wǎng)頁
表單通常用來收集網(wǎng)頁訪問者信息,常見的表單比如搜索引擎的搜索框、各網(wǎng)頁應(yīng)用的注冊或者登陸界面等,通讀本篇對大家的學(xué)習(xí)或工作具有一定的價值,需要的朋友可以參考下2021-10-10js 實現(xiàn) list轉(zhuǎn)換成tree的方法示例(數(shù)組到樹)
這篇文章主要介紹了js 實現(xiàn) list轉(zhuǎn)換成tree的方法示例(數(shù)組到樹),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08JavaScript設(shè)置表單上傳時文件個數(shù)的方法
這篇文章主要介紹了JavaScript設(shè)置表單上傳時文件個數(shù)的方法,可實現(xiàn)動態(tài)增加及刪除表單上傳按鈕的功能,非常簡單實用,需要的朋友可以參考下2015-08-08