关于jQuery插件jTip的修改,代码基本上没变,只进行了简单的修改,我个人认为这样更合适!
2008-08-21 14:51
656 查看
这个jTip插件,我个人认为,有点不太好用,于是个人进行了简单的修改
修改内容如下:
1.由于jtip是将提示信息,用异步html代码方式返回的,所有的内容都写在了href上,我个人认为这样herf很臃肿。
同时,如果href里有?会出错。【也就是说,我有时候真是要写成这个样子<a href="**.aspx?id=**"></a>】报错是不允许的啊,所以就干脆把href里面的异步功能都放在了ref里。
[注意这里用的是rel,起初是想用title的,但是title也是提示,两个提示很难看,于是改成了rel]
2.样式问题,jTip的鼠标提示,把<a>的cursor改成了help,就是指针后面跟着一个?,这个有时候就根本不需要,所以我自己加了一个样式,只有使用
<a href="http://www.yahoo.com" rel="yahoo.htm?width=175" name="Before You Click..." id="yahooCopy" class="jTip">Go To Yahoo</a>使用这种,就是普通的链接变手型。
<a href="#" rel="thanks.htm?width=175" name="感谢JTip的开发者" id="kkai" class="jTip kkai"><font color="#CC6633" style="font-weight:bold;">not a link</font></a>使用这种,就是cuosor;help形状。
/*
* JTip
* By Cody Lindley (http://www.codylindley.com)
* 修改:kkai 2008-8-20
* 建议你有机会去研究下原来的jtip
* Under an Attribution, Share Alike License
* JTip is built on top of the very light weight jquery library.
*/
/*修改内容:
由于jtip是将提示信息,用异步html代码方式返回的,所有的内容都写在了href上,我个人认为这样herf很臃肿。
同时,如果href里有?会出错。
但是,我有时候真是要写成这个样子<a href="**.aspx?id=**"></a>,报错是不允许的啊,所以就干脆把href里面的异步功能都放在了ref里。
[注意这里用的是rel,起初是想用title的,但是title也是提示,两个提示很难看,于是改成了rel]
*/
//页面加载完成时候,调用JT_inint
$(document).ready(JT_init);
function JT_init(){
$("a.jTip")
.hover(function(){JT_show(this.rel,this.id,this.name)},function(){$('#JT').remove()})
//.click(function(){return false}); /*这里被kkai注释掉,因为我需要href连接提交*/
}
function JT_show(rel,linkId,title){
if(title == false)title=" ";
var de = document.documentElement;
var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
var hasArea = w - getAbsoluteLeft(linkId);
var clickElementy = getAbsoluteTop(linkId) - 3; //set y position
var queryString = rel.replace(/^[^/?]+/??/,'');
var params = parseQuery( queryString );
if(params['width'] === undefined){params['width'] = 250};
//if(params['link'] !== undefined){
/*这里被kkai注释掉,我不需要在rel里添加,我不需要onclick window.location*/
//$('#' + linkId).bind('click',function(){window.location = params['link']});
//$('#' + linkId).css('cursor','pointer');
//}
if(hasArea>((params['width']*1)+75)){
$("body").append("<div id='JT' style='width:"+params['width']*1+"px'><div id='JT_arrow_left'></div><div id='JT_close_left'>"+title+"</div><div id='JT_copy'><div class='JT_loader'><div></div></div>");//right side
var arrowOffset = getElementWidth(linkId) + 11;
var clickElementx = getAbsoluteLeft(linkId) + arrowOffset; //set x position
}else{
$("body").append("<div id='JT' style='width:"+params['width']*1+"px'><div id='JT_arrow_right' style='left:"+((params['width']*1)+1)+"px'></div><div id='JT_close_right'>"+title+"</div><div id='JT_copy'><div class='JT_loader'><div></div></div>");//left side
var clickElementx = getAbsoluteLeft(linkId) - ((params['width']*1) + 15); //set x position
}
$('#JT').css({left: clickElementx+"px", top: clickElementy+"px"});
$('#JT').show();
$('#JT_copy').load(rel);
}
function getElementWidth(objectId) {
x = document.getElementById(objectId);
return x.offsetWidth;
}
function getAbsoluteLeft(objectId) {
// Get an object left position from the upper left viewport corner
o = document.getElementById(objectId)
oLeft = o.offsetLeft // Get left position from the parent object
while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
oParent = o.offsetParent // Get parent object reference
oLeft += oParent.offsetLeft // Add parent left position
o = oParent
}
return oLeft
}
function getAbsoluteTop(objectId) {
// Get an object top position from the upper left viewport corner
o = document.getElementById(objectId)
oTop = o.offsetTop // Get top position from the parent object
while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
oParent = o.offsetParent // Get parent object reference
oTop += oParent.offsetTop // Add parent top position
o = oParent
}
return oTop
}
function parseQuery ( query ) {
var Params = new Object ();
if ( ! query ) return Params; // return empty object
var Pairs = query.split(/[;&]/);
for ( var i = 0; i < Pairs.length; i++ ) {
var KeyVal = Pairs[i].split('=');
if ( ! KeyVal || KeyVal.length != 2 ) continue;
var key = unescape( KeyVal[0] );
var val = unescape( KeyVal[1] );
val = val.replace(//+/g, ' ');
Params[key] = val;
}
return Params;
}
function blockEvents(evt) {
if(evt.target){
evt.preventDefault();
}else{
evt.returnValue = false;
}
}
代码下载地址
修改内容如下:
1.由于jtip是将提示信息,用异步html代码方式返回的,所有的内容都写在了href上,我个人认为这样herf很臃肿。
同时,如果href里有?会出错。【也就是说,我有时候真是要写成这个样子<a href="**.aspx?id=**"></a>】报错是不允许的啊,所以就干脆把href里面的异步功能都放在了ref里。
[注意这里用的是rel,起初是想用title的,但是title也是提示,两个提示很难看,于是改成了rel]
2.样式问题,jTip的鼠标提示,把<a>的cursor改成了help,就是指针后面跟着一个?,这个有时候就根本不需要,所以我自己加了一个样式,只有使用
<a href="http://www.yahoo.com" rel="yahoo.htm?width=175" name="Before You Click..." id="yahooCopy" class="jTip">Go To Yahoo</a>使用这种,就是普通的链接变手型。
<a href="#" rel="thanks.htm?width=175" name="感谢JTip的开发者" id="kkai" class="jTip kkai"><font color="#CC6633" style="font-weight:bold;">not a link</font></a>使用这种,就是cuosor;help形状。
/*
* JTip
* By Cody Lindley (http://www.codylindley.com)
* 修改:kkai 2008-8-20
* 建议你有机会去研究下原来的jtip
* Under an Attribution, Share Alike License
* JTip is built on top of the very light weight jquery library.
*/
/*修改内容:
由于jtip是将提示信息,用异步html代码方式返回的,所有的内容都写在了href上,我个人认为这样herf很臃肿。
同时,如果href里有?会出错。
但是,我有时候真是要写成这个样子<a href="**.aspx?id=**"></a>,报错是不允许的啊,所以就干脆把href里面的异步功能都放在了ref里。
[注意这里用的是rel,起初是想用title的,但是title也是提示,两个提示很难看,于是改成了rel]
*/
//页面加载完成时候,调用JT_inint
$(document).ready(JT_init);
function JT_init(){
$("a.jTip")
.hover(function(){JT_show(this.rel,this.id,this.name)},function(){$('#JT').remove()})
//.click(function(){return false}); /*这里被kkai注释掉,因为我需要href连接提交*/
}
function JT_show(rel,linkId,title){
if(title == false)title=" ";
var de = document.documentElement;
var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
var hasArea = w - getAbsoluteLeft(linkId);
var clickElementy = getAbsoluteTop(linkId) - 3; //set y position
var queryString = rel.replace(/^[^/?]+/??/,'');
var params = parseQuery( queryString );
if(params['width'] === undefined){params['width'] = 250};
//if(params['link'] !== undefined){
/*这里被kkai注释掉,我不需要在rel里添加,我不需要onclick window.location*/
//$('#' + linkId).bind('click',function(){window.location = params['link']});
//$('#' + linkId).css('cursor','pointer');
//}
if(hasArea>((params['width']*1)+75)){
$("body").append("<div id='JT' style='width:"+params['width']*1+"px'><div id='JT_arrow_left'></div><div id='JT_close_left'>"+title+"</div><div id='JT_copy'><div class='JT_loader'><div></div></div>");//right side
var arrowOffset = getElementWidth(linkId) + 11;
var clickElementx = getAbsoluteLeft(linkId) + arrowOffset; //set x position
}else{
$("body").append("<div id='JT' style='width:"+params['width']*1+"px'><div id='JT_arrow_right' style='left:"+((params['width']*1)+1)+"px'></div><div id='JT_close_right'>"+title+"</div><div id='JT_copy'><div class='JT_loader'><div></div></div>");//left side
var clickElementx = getAbsoluteLeft(linkId) - ((params['width']*1) + 15); //set x position
}
$('#JT').css({left: clickElementx+"px", top: clickElementy+"px"});
$('#JT').show();
$('#JT_copy').load(rel);
}
function getElementWidth(objectId) {
x = document.getElementById(objectId);
return x.offsetWidth;
}
function getAbsoluteLeft(objectId) {
// Get an object left position from the upper left viewport corner
o = document.getElementById(objectId)
oLeft = o.offsetLeft // Get left position from the parent object
while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
oParent = o.offsetParent // Get parent object reference
oLeft += oParent.offsetLeft // Add parent left position
o = oParent
}
return oLeft
}
function getAbsoluteTop(objectId) {
// Get an object top position from the upper left viewport corner
o = document.getElementById(objectId)
oTop = o.offsetTop // Get top position from the parent object
while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
oParent = o.offsetParent // Get parent object reference
oTop += oParent.offsetTop // Add parent top position
o = oParent
}
return oTop
}
function parseQuery ( query ) {
var Params = new Object ();
if ( ! query ) return Params; // return empty object
var Pairs = query.split(/[;&]/);
for ( var i = 0; i < Pairs.length; i++ ) {
var KeyVal = Pairs[i].split('=');
if ( ! KeyVal || KeyVal.length != 2 ) continue;
var key = unescape( KeyVal[0] );
var val = unescape( KeyVal[1] );
val = val.replace(//+/g, ' ');
Params[key] = val;
}
return Params;
}
function blockEvents(evt) {
if(evt.target){
evt.preventDefault();
}else{
evt.returnValue = false;
}
}
代码下载地址
相关文章推荐
- 个人认为比较有用的jquery插件
- JQuery插件让图片旋转任意角度且代码极其简单
- jquery简单的tab切换特效插件jquery-tab demo代码下载
- jQuery插件如何编写04_ 简单的全选反选插件(关联了主复选框和子复选框,代码简单)
- jQuery 简单插件开发代码
- 个人认为不错的代码结构:利用switch case语句进行参数的取值校验
- Visual Studio 2017中使用正则修改部分内容 如何使用ILAsm与ILDasm修改.Net exe(dll)文件 C#学习-图解教程(1):格式化数字字符串 小程序开发之图片转Base64(C#、.Net) jquery遍历table为每一个单元格取值及赋值 。net加密解密相关方法 .net关于坐标之间一些简单操作
- 关于SubSonic3.0插件使用Json反序列化获得的实体进行更新操作时,只能执行添加而不能执行修改(编辑)操作的处理
- 扩展Jquery的resize方法(原生的resize只针对window,因项目需要扩展了此方法,目前只在DIV上使用过,后续如果修改代码会对此代码进行更新)
- 这是我以前copy的关于多线程 4000 下载代码,来源我忘记了,我进行了注解。个人认知,不详细之处还请谅解
- jquery叫你怎样对图层进行隐藏和现实 一行代码超简单
- 拒绝插件wordpress首页利用代码进行文章字符串截取(转自www.jqueryba.com)
- JQuery插件让图片旋转任意角度且代码极其简单 - 摘自网友
- jquery数据验证插件(自制,简单,练手)实例代码
- jquery中实现简单的tabs插件功能的代码
- 个人认为是比较完整的自动完成插件(jquery)
- 关于jquery插件datatables的简单应用
- 关于SubSonic3.0插件使用实体进行更新操作时(执行T.Update()或T.Save()),某些列无法进行修改操作的问题处理
- 基于Jquery的简单&简陋Tabs插件代码
- JQuery插件让图片旋转任意角度且代码极其简单