> 呵呵,这次讲一讲 jQuery 鼠标悬停时候的元素弹动效果,还有重要的内联元素概念。
> 元素弹动是指鼠标悬停某个元素,比如 DIV 上的时候,DIV 会向某个方向弹过去。

> 如图分别使用了 Display:block 与使用 Display:inline 的 CSS 效果代码,左边的并不美观。
> 而右边的非常在整齐,这就是神奇并且必备的 Display 参数,而 Inline 表示此元素为内联元素。
1. 关于Display的属性:

2. 使用 Display:block 实现可移动效果:
> 好吧,实际上 Inline 和今天要说的 jQuery 的关系是反的。因为我们用了 Inline 就不能使用弹动效果了。
> 内联元素就是在一行内的元素,只能放在行内;块级元素,就是一个四方块,可以放在页面上任何地方。
> 因为 Inline 是内联元素,而 Block 是块级元素,所以这里只能使用 Block 来实现此效果。
> 至于把那些字给水平居中就使用 padding-top:0.5em; 即可,顶部填充0.5个字的长度。
> 下面的代码可以使 Id 为 momo 的 DIV 实现弹动效果。
jQuery(document).ready(function($){
$("#momo").hover(function (){
$(this).stop().animate({marginTop:"15px"}, 350,"easeOutBounce");
}
,function () {
$(this).stop().animate({marginTop:"0px"}, 150,"easeOutBounce");
});
});
});
> 同时需要 Jquery.easing 插件的支持,所以请将以下代码加入你的 JS文件。
> 灵活使用 Jquery.easing 插件可以实现很多弹动效果,更多的请询问谷歌,谢谢 ^_^。
3. Jquery.easing 插件代码:
> 下面是灰常强大的 Jquery.easing.1.3 的全部代码,去掉了些没营养的东西:
// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend( jQuery.easing,
{
def: 'easeOutQuad',
swing: function (x, t, b, c, d) {
//alert(jQuery.easing.default);
return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
},
easeInQuad: function (x, t, b, c, d) {
return c*(t/=d)*t + b;
},
easeOutQuad: function (x, t, b, c, d) {
return -c *(t/=d)*(t-2) + b;
},
easeInOutQuad: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t + b;
return -c/2 * ((--t)*(t-2) - 1) + b;
},
easeInCubic: function (x, t, b, c, d) {
return c*(t/=d)*t*t + b;
},
easeOutCubic: function (x, t, b, c, d) {
return c*((t=t/d-1)*t*t + 1) + b;
},
easeInOutCubic: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t + b;
return c/2*((t-=2)*t*t + 2) + b;
},
easeInQuart: function (x, t, b, c, d) {
return c*(t/=d)*t*t*t + b;
},
easeOutQuart: function (x, t, b, c, d) {
return -c * ((t=t/d-1)*t*t*t - 1) + b;
},
easeInOutQuart: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
return -c/2 * ((t-=2)*t*t*t - 2) + b;
},
easeInQuint: function (x, t, b, c, d) {
return c*(t/=d)*t*t*t*t + b;
},
easeOutQuint: function (x, t, b, c, d) {
return c*((t=t/d-1)*t*t*t*t + 1) + b;
},
easeInOutQuint: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
return c/2*((t-=2)*t*t*t*t + 2) + b;
},
easeInSine: function (x, t, b, c, d) {
return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
},
easeOutSine: function (x, t, b, c, d) {
return c * Math.sin(t/d * (Math.PI/2)) + b;
},
easeInOutSine: function (x, t, b, c, d) {
return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
},
easeInExpo: function (x, t, b, c, d) {
return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
},
easeOutExpo: function (x, t, b, c, d) {
return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
},
easeInOutExpo: function (x, t, b, c, d) {
if (t==0) return b;
if (t==d) return b+c;
if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
},
easeInCirc: function (x, t, b, c, d) {
return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
},
easeOutCirc: function (x, t, b, c, d) {
return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
},
easeInOutCirc: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
},
easeInElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
},
easeOutElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
},
easeInOutElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
},
easeInBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c*(t/=d)*t*((s+1)*t - s) + b;
},
easeOutBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
},
easeInOutBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
},
easeInBounce: function (x, t, b, c, d) {
return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
},
easeOutBounce: function (x, t, b, c, d) {
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
}
},
easeInOutBounce: function (x, t, b, c, d) {
if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
}
});
jq是不是也算前台设计?
@漠岚 , 是的 jQuery 属于 JavaScript ~
而前端技术有 JavaScript VBScript CSS HTML DHTML ~
PHP ASP 什么的就是后台了 ~
深奥啊
@疾风 , 咦 我最近被阅读器整的老纠结的 ~
貌似早就订阅你了 怎么没有的 ~
再订阅下 希望不会再那么诡异 ~
我也看不明白
@Awu , 呵呵,阿吴是C++高手 ~
那个表格有用
@阿士 , 呵呵,谢谢支持 ~
额,寒假要学JS了。。
@ShuaiGe.Me , 恩 JS很有用的说 ~
太专业了,先飘过
@万戈 , ( ⊙o⊙ )哇 万戈也来啦 ~
灰常欢迎 ~
话说你的 CSSTidy 很好用,呵呵 ~
我迅速的扫过~ :confused:
@Auston Jary , 呵呵,我想我最近发文难易相间比较好 ~ O(∩_∩)O ~
不懂JS~~不过有空可以~~尝试下
@keon , 恩,我以前以为JS不算什么 ~
现在发现不可或缺呢 ~
@keon , 汗 ~ 你的网址貌似打错了 ~
我点连接进去是一个空站点 ~
@邪 罗刹,
呃~~~貌似没打错~~~奇怪啊~~
@邪 罗刹,
看了下~~链接是http://www.keon.org/
但我打的确实是http://www.xunlu.org~~郁闷·~
@邪 罗刹 , 汗 呵呵 ~~ 等下去转转 \(^o^)/ ~
@keon , 汗 呵呵 ~~ 等下去转转 \(^o^)/ ~
分享是精神,Ajax有必要学习
@光卫 , 呵呵,谢谢 ~ 我也加油去学AJAX ~
饿 实际上 jQuery和AJAX没关系的 ~
------
( ⊙o⊙ )哇 童鞋 你对销售很有研究呢 ~
太难懂了,没接触这个
@九站 , 呵呵,慢慢来,有兴趣的话研究研究 ~
@邪 罗刹,
我可研究不来,你自己慢慢玩吧。
easeOutBounce 这个参数是起什么作用的
@610 , 呵呵 ~ 是使元素下拉 ~
@邪 罗刹,
你用的是什么评论邮件提醒插件,麻烦分享一下。
@610 , 呵呵 早就分享了 ~
连邮件的样式都分享了 ~
http://www.evlos.org/2009/11/30/share-my-comments-reply-mail-sourcecode/
这个效果挺不错,喜欢jquery 的效果,呵呵
@开心凡人 , 恩,很平滑,很爽 ~ 哈哈 ~ :biggrin:
很详细