javascript代码实例教程-jQuery实现的Div窗口震动特效

发布时间:2018-12-22 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-jQuery实现的Div窗口震动特效脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

jQuery实现的Div窗口震动特效代码如下:


<!DOCTYPE htML PubLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html XMlns="https://www.w3.org/1999/xhtml">
<head>
<;meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<tITle>jquery窗口震动特效</title>
<script type="text/javascript" src="https://www.codefans.net/ajaxjs/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
;(function($){
VAR element = {};
$.fn.jshaker = function(){
element = $(this);
element.css(&#39;position', 'relative');
element.find('*').each(function(i, el){
$(el).css('position', 'relative');
});
var iFunc = function(){ $.fn.jshaker.aniMATE($(element)); };
setTimeout(iFunc, 50);
};
$.fn.jshaker.animate = function(el){
$.fn.jshaker.shake(el);
el.find('*').each(function(i, el){
$.fn.jshaker.shake(el);
});
var iFunc = function(){ $.fn.jshaker.animate(el); };
setTimeout(iFunc, 50);
}
$.fn.jshaker.shake = function(el){
var pos = $(el).position();
if(Math.random() > 0.5){
$(el).css('top', pos['top'] + Math.random() * 20 < 10 ? (Math.random() * 20 * (-1)) : Math.random() * 20);
} else {
$(el).css('left', pos['left'] + Math.random() * 20 < 10 ? (Math.random() * 20 * (-1)) : Math.random() * 20);
}
}
})(jQuery);
</script>
<script type="text/javascript">
$(document).ready(function(){
$('.block').click(function(){
$(this).jshaker();
});
});
</script>
<style type="text/css">
BODY{font-family: "Lucida Grande", Arial, Helvetica, sans-serif;color: #666666;font-Size: 12px;background: #FFFFFF;}
A{color: #0A8ECC;}
A: HOVER{text-decoration: none;color: #8fcB2F;}
h1{font-weight: normal;color: #0A8ECC;margin: 0;padding: 0;}
BODY{margin: 20px;padding: 20px;}
strong{color: #000000;}
.vspACER{height: 20px;}
PRE.code{padding: 7px;background: #777777;color: #F0F0F0;width: 400px;overflow: auto;}
#content-area{border: 3px solid #CCCCCC;background: #F0F0F0;padding: 10px;width: 500px;}
P.script-link{clear: both;padding: 10px 0;border-top: 1px dotted #CCCCCC;}
#content .block {float: left;border: 1px solid #CCCCCC;background: #F0F0F0;padding: 10px;margin: 10px;width: 300px;}
</style>
</head>
<body>
<p id="page">
<h1>jquery窗 口 震 动 特 效</h1>
<p id="content">
<p class="block">
<p>点击本框内,可实现震动</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>
Item 3
<ul>
<li>Sub Item 1</li>
<li>Sub Item 2</li>
<li>Sub Item 3</li>
<li>Sub Item 4</li>
<li>Sub Item 5</li>
</ul>
</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</p>
<p class="block">
<form action="#">
<p><label for="inp1">Text Field 1:</label><input type="text" name="inp1" id="inp1" value="" /></p>
<p><label for="inp2">Text Field 2:</label><input type="text" name="inp2" id="inp2" value="" /></p>
<p><button type="submit">Submit</button></p>
</form>
</p>
</p>
<p class="script-link">
</p>
</p>
</body>
</html>

觉得可用,就经常来吧! 脚本宝典 欢迎评论哦!&nbsp;js脚本,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的javascript代码实例教程-jQuery实现的Div窗口震动特效全部内容,希望文章能够帮你解决javascript代码实例教程-jQuery实现的Div窗口震动特效所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。