教你用mootools1.2写个简单提示特效!

虽然mootools有自带的tips特效,但是样式固定,而且我发现mootools那个Tips有时候会报错的,假如你在ie中进我博客时,马上把鼠标移动到那个‘Chromatography Ads’下面的那些小色块上面,很有可能会马上弹出个对话框说’http://xiebiji.com。’打不开的提示,留意一下那个地址最后多了一个句号,那当然打不开啦。我被这个问题郁闷了很久,最后还是没有解决。

所以今天特意把之前写过的tips特效从网页中提取出来:
先看看效果:http://xiebiji.com/works/tips/

html代码如下:

<body>
        <img class="tips" title="I am an image." src="http://xiebiji.com/wp-content/themes/corel/images/noimg.gif" alt="" />
	<ul>
            <li class="tips" title="click to browse ‘xiebiji.com’"><a href="xiebiji.com" >xiebiji.com</a></li>
            <li class="tips" title="I am a link."><a href="" >A Link</a></li>
        </ul>     
</body>

css代码如下:

body{
background:#000;
}
a{
font-family:Arial, Helvetica, sans-serif;
color:#FFF;
text-decoration:none;
}
ul{
margin:0;
padding:0;
}
li{
float:left;
margin:5px 10px 0 0;
background:#666666;
padding:4px 20px;
}
/*气泡样式*/
.bubble{
background:url(images/bubblex.gif) repeat-x;
position:absolute;
top:0;
left:0;
z-index:100000;
}
.bubbleLeft{
background:url(images/bubbleLeft.gif) no-repeat left;
float:left;
}
.bubbleRight{
height:41px;
padding:0 18px;
background:url(images/bubbleRight.gif) no-repeat right;
float:left;
}
#bubbleFont{
display:block;
line-height:30px;
color:#000;
font-family:Arial, Helvetica, sans-serif;
float:left;
overflow:hidden;
}

mootools代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
window.addEvent('domready',function(){
		tip('.tips');
});
function tip(els){
		var el1=new Element('div',{'class':'bubble'});
		el1.setStyle('opacity',0);
		var el2=new Element('div',{'class':'bubbleLeft'});
		var el3=new Element('div',{'class':'bubbleRight'});
		var el4=new Element('span',{'id':'bubbleFont'});
		el4.inject(el3);
		el3.inject(el2);
		el2.inject(el1);
		el1.inject($$('body')[0]);
                //以上步骤生成气泡所需html代码
		$$(els).each(function(e){//为所有class属性包含els的元素初始化
			e.addEvent('mouseenter',function(event){//鼠标进入时触发
				mx=event.page.x+20;//获取浏览器x坐标并且偏移20px
				my=event.page.y-40;//同理
				note=this.get('title');//提示的信息由元素的title属性提供
				$('bubbleFont').set('text',note);
				el1.setStyles({
					'left':mx,
					'top':my
				});
				el1.tween('opacity',1);//变换透明度到1
			});
			e.addEvent('mousemove',function(event){//鼠标移动时触发
				mx=event.page.x+20;
				my=event.page.y-40;
				el1.setStyles({
					'left':mx,
					'top':my
				});
			});
			e.addEvent('mouseleave',function(event){//鼠标离开时触发
				el1.tween('opacity',0);//变换透明度到0
			});
		});
}

那个方法很简单,有需要的朋友要是不明白就留言吧^_^!
原创文章,转载请注明出处:http://xiebiji.com/2009/02/tips 作者:Joe Zhou

6 Responses to 教你用mootools1.2写个简单提示特效!... »

  1. 小桥流水人家 评论 2009-02-15 17:19

    又见html高手~
    最近好吗

    回复

    joe 回复 二月 15th, 2009 at 19:47

    最近很累。。

    回复

  2. DiDi 评论 2009-02-16 19:32

    不是很懂~不过支持一下~哈~

    回复

  3. wing 评论 2009-03-16 17:05

    小joe有没接触过extJS?一个很强大的JS类库,做出来的表格很强大,可以用ctrl全选、逐个选择,还可以实现网页某个部分伸缩、很漂亮的弹出窗口,etc。
    不知mootools的强大之处在哪?有空也要去学学~

    回复

    joe 回复 三月 16th, 2009 at 17:33

    :( extjs之前听说过。。但是一直没有学。。。mootools强大之处啊?这个我也很难说,我也学的是皮毛

    回复

  4. hellowang 评论 2010-10-14 13:16

    网站好漂亮啊 ^ ^

    回复

Leave a Reply

Email address is not published

You should say a Chinese word to pass spam check. If you can not input Chinese, just copy 你好 and paste them into comment text box.