jquery+css3實(shí)現(xiàn)會(huì)動(dòng)的小圓圈效果
本文實(shí)例講述了jquery+css3實(shí)現(xiàn)會(huì)動(dòng)的小圓圈效果。分享給大家供大家參考,具體如下:
運(yùn)行效果截圖如下:

具體代碼如下:
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<title>那些變換顏色的小豆豆</title>
<script type="text/javascript" src="jquery.js"></script>
<style type="text/css">
h1{font-size:16px;}
.circle
{
position:absolute;
width:100px;
height:100px;
border-radius: 50px;
-webkit-border-radius:50px;
-moz-border-radius:50px;
-o-border-radius:50px;
-ms-border-radius:50px;
border:1px solid #ddd;
background-color:#eee;
text-align:center;
-moz-transition:background-color .5s ease-in;
-webkit-transition:background-color .5s ease-in;
-o-transition:background-color .5s ease-in;
-ms-transition:background-color .5s ease-in;
transition:background-color .5s ease-in;
}
</style>
<script type="text/javascript" >
var colorArray = "ABCDEFabcdef1234567890".split('');
function createCircle(position, size){
var html = [];
var radius = size.height > size.width ? size.height/2 : size.width / 2;
var opacity = Math.random();
opacity = opacity < 0.3 ? opacity = 0.3 : opacity;
html.push('<div class="circle" style="left:'+position.left+'px; top:'+position.top+'px;');
html.push('width:'+size.width+'px; height:'+size.height+'px; ');
html.push('border-radius:'+radius+'px;');
html.push('-webkit-border-radius:'+radius+'px;');
html.push('-moz-border-radius:'+radius+'px;');
html.push('-o-border-radius:'+radius+'px;');
html.push('-ms-border-radius:'+radius+'px;');
html.push('opacity:'+opacity+';');
html.push('filter:alpha(opacity='+Math.round(opacity*100)+')');
html.push('" ></div>');
return html.join('');
}
function createColor(){
var color = "";
for(var i=0; i<6; i++) {
color += colorArray[Math.ceil(Math.random()*21)];
}
return "#"+color;
}
function animate(obj){
setInterval(function(){
var position = obj.position();
var left = parseInt(position.left);
var top = parseInt(position.top);
obj.css('background-color', createColor());
obj.animate({'left': left + 5}, 250);
obj.animate({'left': left - 5, 'top': top + 5}, 250);
obj.animate({'top': top}, 250);
obj.animate({'left': left, 'top': top}, 250);
}, 1000);
}
$(document).ready(function(){
var wrapper = $("#wrapper");
var height = parseInt(document.documentElement.clientHeight || 500);
var width = parseInt(wrapper.width());
for(var i=0; i<200; i++) {
var position = {
left: Math.round(Math.random()*(width - 50)),
top: Math.round(Math.random()*(height - 100))
};
var _size = 50 - Math.round(Math.random()*40);
var size = {
height: _size,
width: _size
};
var circle = $(createCircle(position, size));
circle.appendTo(wrapper);
circle.mouseover(function(){
var color = createColor();
$(this).css('background-color', color);
}).mouseout(function(){
var color = createColor();
$(this).css('background-color', color);
});
animate(circle);
}
});
</script>
</head>
<body id="wrapper">
<div id="wrapper">
</div>
</body>
</html>
更多關(guān)于jQuery特效相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《jQuery常見(jiàn)經(jīng)典特效匯總》及《jQuery動(dòng)畫(huà)與特效用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- 使用jquery+CSS3實(shí)現(xiàn)仿windows10開(kāi)始菜單的下拉導(dǎo)航菜單特效
- jQuery僅用3行代碼實(shí)現(xiàn)的顯示與隱藏功能完整實(shí)例
- jQuery+CSS3折疊卡片式下拉列表框?qū)崿F(xiàn)效果
- 程序員必知35個(gè)jQuery 代碼片段
- jQuery Uploadify 上傳插件出現(xiàn)Http Error 302 錯(cuò)誤的解決辦法
- 解決jQuery上傳插件Uploadify出現(xiàn)Http Error 302錯(cuò)誤的方法
- 基于jQuery和CSS3制作響應(yīng)式水平時(shí)間軸附源碼下載
- jQuery 3.0 的變化及使用方法
- 酷炫jQuery全屏3D焦點(diǎn)圖動(dòng)畫(huà)效果
- 即將發(fā)布的jQuery 3 有哪些新特性
相關(guān)文章
Jquery多選框互相內(nèi)容交換的實(shí)例代碼
這篇文章介紹了Jquery多選框互相內(nèi)容交換的實(shí)例代碼,有需要的朋友可以參考一下2013-07-07
jQuery Pagination Ajax分頁(yè)插件(分頁(yè)切換時(shí)無(wú)刷新與延遲)中文翻譯版
此jQuery插件為Ajax分頁(yè)插件,一次性加載,故分頁(yè)切換時(shí)無(wú)刷新與延遲,如果數(shù)據(jù)量較大不建議用此方法,因?yàn)榧虞d會(huì)比較慢,接下來(lái)詳細(xì)介紹使用方法,感興趣的朋友可以了解下2013-01-01
jQuery 跨域訪(fǎng)問(wèn)解決原理案例詳解
這篇文章主要介紹了jQuery 跨域訪(fǎng)問(wèn)解決原理案例詳解的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07
jQuery中clearQueue()方法用法實(shí)例
這篇文章主要介紹了jQuery中clearQueue()方法用法,實(shí)例分析了clearQueue()方法的功能、定義及進(jìn)行清空隊(duì)列操作的技巧,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-12-12
把html頁(yè)面的部分內(nèi)容保存成新的html文件的jquery代碼
把html頁(yè)面的部分內(nèi)容保存成新的html文件,用到了jquery的獲取指定id的內(nèi)容。然后保存代碼。2009-11-11
模擬jQuery ajax服務(wù)器端與客戶(hù)端通信的代碼
本案例通過(guò)jQuery和Servlet技術(shù)來(lái)判斷用戶(hù)名是否存在,讓讀者明白jQuery是怎么調(diào)用服務(wù)器后臺(tái)的。還給出了解決中文亂碼的方案和如何避免各種瀏覽器的緩存。2011-03-03
EasyUI 結(jié)合JS導(dǎo)出Excel文件的實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇EasyUI 結(jié)合JS導(dǎo)出Excel文件的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-11-11
jQuery中使用了document和window哪些屬性和方法小結(jié)
未列出常見(jiàn)的比如document.getElementById(),object.addEventListener()等。2011-09-09
jQuery焦點(diǎn)圖輪播插件KinSlideshow用法分析
這篇文章主要介紹了jQuery焦點(diǎn)圖輪播插件KinSlideshow用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了jQuery焦點(diǎn)圖輪播插件KinSlideshow的參數(shù)含義與使用方法,需要的朋友可以參考下2016-06-06

