jQuery實(shí)現(xiàn)網(wǎng)頁抖動(dòng)的菜單抖動(dòng)效果
本文實(shí)例講述了jQuery實(shí)現(xiàn)網(wǎng)頁抖動(dòng)的菜單抖動(dòng)效果。分享給大家供大家參考。具體如下:
這里的jQuery抖動(dòng)導(dǎo)航菜單效果,兼容IE7/8/9及其它主流瀏覽器,使用方法:先引入jQuery腳本庫和jquery.shake.js文件,然后在需要的元素上調(diào)用shake( )方法,例如想使整個(gè)頁面抖動(dòng),則這么寫:$('body').shake( ),調(diào)用上述方法后,將鼠標(biāo)移至指定的元素,該元素就會(huì)抖動(dòng)。
運(yù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=gb2312" />
<style type="text/css">
body { background-color: lightgreen; }
#demo, #demo *, #footer, #footer * { margin: 0; padding: 0; }
#demo, #footer { width: 70%; margin: 1em auto; font: normal 1em/1.4em 微軟雅黑; }
#demo ul { list-style: none; overflow: hidden; background-color: rgb(241, 241, 241); padding: 1em 0; }
#demo ul li { float: left; width: 10%; text-align: center; cursor: pointer; padding: .3em 0; color: #262626; }
#demo ul li:hover { background-color: #D4D4D4; }
#msg { font-size: 1.2em; text-align: center; margin: 2em 0; }
#footer { font-size: .8em; }
#footer p { margin: .3em 0; }
#footer a { color: rgb(126, 34, 34); text-decoration: none; }
#footer a:hover { text-decoration: underline; }
#footer a:visited { color: rgb(187, 166, 166); }
</style>
<title>jQuery抖動(dòng)導(dǎo)航菜單效果</title>
<script src="jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
(function ($) {
$.fn.shake = function (s) {
var t = { rangeX: 2, rangeY: 2, rangeRot: 1, rumbleSpeed: 10, rumbleEvent: 'hover', posX: 'left', posY: 'top' }, u = $.extend(t, s);
return this.each(function () {
var $obj = $(this)
, f
, g = u.rangeX * 2
, h = u.rangeY * 2
, i = u.rangeRot * 2
, j = u.rumbleSpeed
, k = $obj.css('position')
, l = u.posX
, m = u.posY
, n
, o
, p
, q = { 'position': k, '-webkit-transform': 'rotate(0deg)', '-moz-transform': 'rotate(0deg)', '-o-transform': 'rotate(0deg)', 'transform': 'rotate(0deg)' };
if (l === 'left') {
n = parseInt($obj.css('left'), 10)
}
if (l === 'right') {
n = parseInt($obj.css('right'), 10)
}
if (m === 'top') {
o = parseInt($obj.css('top'), 10)
}
if (m === 'bottom') {
o = parseInt($obj.css('bottom'), 10)
}
function rumbler(a) {
var b = Math.random()
, c = Math.floor(Math.random() * (g + 1)) - g / 2
, d = Math.floor(Math.random() * (h + 1)) - h / 2
, e = Math.floor(Math.random() * (i + 1)) - i / 2;
if (a.css('display') === 'inline') {
p = true;
a.css('display', 'inline-block')
}
if (c === 0 && g !== 0) {
c = b < .5 ? 1 : -1;
}
if (d === 0 && h !== 0) {
d = b < .5 ? 1 : -1;
}
if (k === 'absolute') {
a.css({ 'position': 'absolute', '-webkit-transform': 'rotate(' + e + 'deg)', '-moz-transform': 'rotate(' + e + 'deg)', '-o-transform': 'rotate(' + e + 'deg)', 'transform': 'rotate(' + e + 'deg)' });
a.css(l, n + c + 'px');
a.css(m, o + d + 'px')
}
if (k === 'fixed') {
a.css({ 'position': 'fixed', '-webkit-transform': 'rotate(' + e + 'deg)', '-moz-transform': 'rotate(' + e + 'deg)', '-o-transform': 'rotate(' + e + 'deg)', 'transform': 'rotate(' + e + 'deg)' });
a.css(l, n + c + 'px');
a.css(m, o + d + 'px')
}
if (k === 'static' || k === 'relative') {
a.css({ 'position': 'relative', '-webkit-transform': 'rotate(' + e + 'deg)', '-moz-transform': 'rotate(' + e + 'deg)', '-o-transform': 'rotate(' + e + 'deg)', 'transform': 'rotate(' + e + 'deg)' });
a.css(l, c + 'px');
a.css(m, d + 'px')
}
}
if (u.rumbleEvent === 'hover') {
$obj.hover(function () {
var a = $(this);
f = setInterval(function () {
rumbler(a)
}, j)
}, function () {
var a = $(this);
clearInterval(f);
a.css(q);
a.css(l, n + 'px');
a.css(m, o + 'px');
if (p === true) {
a.css('display', 'inline')
}
});
}
if (u.rumbleEvent === 'click') {
$obj.toggle(function () {
var a = $(this);
f = setInterval(function () {
rumbler(a)
}, j)
}, function () {
var a = $(this);
clearInterval(f);
a.css(q);
a.css(l, n + 'px');
a.css(m, o + 'px');
if (p === true) {
a.css('display', 'inline')
}
});
}
if (u.rumbleEvent === 'mousedown') {
$obj.bind({
mousedown: function () {
var a = $(this);
f = setInterval(function () {
rumbler(a)
}, j)
}, mouseup: function () {
var a = $(this);
clearInterval(f);
a.css(q);
a.css(l, n + 'px');
a.css(m, o + 'px');
if (p === true) {
a.css('display', 'inline')
}
}, mouseout: function () {
var a = $(this);
clearInterval(f);
a.css(q);
a.css(l, n + 'px');
a.css(m, o + 'px');
if (p === true) {
a.css('display', 'inline')
}
}
});
}
if (u.rumbleEvent === 'constant') {
var r = $(this);
f = setInterval(function () {
rumbler(r)
}, j);
}
});
}
}(jQuery));
</script>
</head>
<body>
<div id="demo">
<ul>
<li>首頁</li>
<li>ASP</li>
<li>PHP</li>
<li>JSP</li>
<li>DELPHI</li>
<li>VC++</li>
<li>C#</li>
<li>VB</li>
<li>.NET</li>
</ul>
<div id="msg">將鼠標(biāo)移動(dòng)到導(dǎo)航條上查看效果</div>
</div>
<script type="text/javascript">
$('#demo li').shake();
</script>
</body>
</html>
希望本文所述對大家的jquery程序設(shè)計(jì)有所幫助。
- jquery仿京東導(dǎo)航/仿淘寶商城左側(cè)分類導(dǎo)航下拉菜單效果
- jQuery仿京東商城樓梯式導(dǎo)航定位菜單
- jQuery模仿京東/天貓商品左側(cè)分類導(dǎo)航菜單效果
- jQuery簡單實(shí)現(xiàn)仿京東商城的左側(cè)菜單效果代碼
- Jquery實(shí)現(xiàn)仿京東商城省市聯(lián)動(dòng)菜單
- jQuery簡單實(shí)現(xiàn)仿京東分類導(dǎo)航層效果
- jquery仿京東側(cè)邊欄導(dǎo)航效果
- 使用jquery菜單插件HoverTree仿京東無限級菜單
- jQuery和CSS仿京東仿淘寶列表導(dǎo)航菜單
- jQuery實(shí)現(xiàn)仿京東防抖動(dòng)菜單效果示例
相關(guān)文章
巧用jquery解決下拉菜單被Div遮擋的相關(guān)問題
本篇文章主要是對巧用jquery解決下拉菜單被Div遮擋的相關(guān)問題進(jìn)行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-02-02
jQuery.Form實(shí)現(xiàn)Ajax上傳文件同時(shí)設(shè)置headers的方法
這篇文章主要介紹了jQuery.Form實(shí)現(xiàn)Ajax上傳文件同時(shí)設(shè)置headers的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-06-06
jquery仿百度百科底部浮動(dòng)導(dǎo)航特效
這篇文章主要介紹了jquery仿百度百科底部浮動(dòng)導(dǎo)航特效,需要的朋友可以參考下2015-08-08
jQuery Validate表單驗(yàn)證插件 添加class屬性形式的校驗(yàn)
這篇文章主要介紹了jQuery Validate表單驗(yàn)證插件,在class屬性中添加校驗(yàn)規(guī)則進(jìn)行簡單的校驗(yàn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-01-01
jquery實(shí)現(xiàn)圖片水平滾動(dòng)效果代碼分享
這篇文章主要介紹了jquery實(shí)現(xiàn)圖片水平滾動(dòng)效果,很實(shí)用的代碼,推薦給大家,有需要的小伙伴可以參考下。2015-08-08

