最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jquery點(diǎn)擊頁(yè)面任何區(qū)域?qū)崿F(xiàn)鼠標(biāo)焦點(diǎn)十字效果

 更新時(shí)間:2013年06月21日 16:52:01   作者:  
鼠標(biāo)點(diǎn)擊聚焦,地圖定位,在圖片上突出顯示,焦點(diǎn)定位頁(yè)面元素,這些都是在系統(tǒng)開(kāi)發(fā)是經(jīng)常需要用到的,下面為大家介紹下具體的實(shí)現(xiàn),感興趣的朋友可以參考下哈
系統(tǒng)開(kāi)發(fā)時(shí)很多地方需要有焦點(diǎn)效果,例如:鼠標(biāo)點(diǎn)擊聚焦,地圖定位,在圖片上突出顯示,焦點(diǎn)定位頁(yè)面元素。
本小功能通過(guò)jquery和graphics二次開(kāi)發(fā),實(shí)現(xiàn)通過(guò)鼠標(biāo)點(diǎn)擊頁(yè)面任何區(qū)域,聚焦當(dāng)前點(diǎn)擊位置。適用于頁(yè)面任何元素的位置效果。
首先引入jquery引擎包:jquery-1.4.2.min.js和graphics.js
源碼下載地址
編寫(xiě)實(shí)現(xiàn)效果js文件,qfocus.js,源碼如下:
復(fù)制代碼 代碼如下:

var qfocus = {
config:{
"bar_dis":true,//橫豎條顯示或隱藏
"circle_dis":true,//焦點(diǎn)隱藏
"bar_color":"black",//線(xiàn)條顏色
"circle_color":"red",//圓圈顏色
"rect_color":"green"http://方塊顏色
},
locationTimer: null,//時(shí)間控制標(biāo)識(shí)符
onmouseClick: function(ev){//鼠標(biāo)點(diǎn)擊獲取鼠標(biāo)位置畫(huà)聚焦效果
var point = this.mousePosition(ev);
this.showFocus(point);
},
onclickElement:function(obj) {//鼠標(biāo)點(diǎn)擊獲取坐標(biāo)做焦點(diǎn)
var _point = this.elementPosition(obj);
this.showFocus(_point);
},
showFocus:function (point) {//顯示焦點(diǎn)效果
if (this.locationTimer) {
clearTimeout(this.locationTimer);
} //清除定時(shí)器
var mapDiv = "#mapdiv";
var _point = point;
var canvas = $("#canvas");
var vLine = $("#vline");
var hLine = $("#hline");
//焦點(diǎn)隱藏或顯示
if (this.config["circle_dis"] == true) {
if (!$("#canvas").attr("id")) {
canvas = '<div id="canvas" style="left:' + (_point.x - 25) + 'px;top:' + (_point.y - 25) + 'px;width:50px;height:50px;overflow:hidden;position:absolute;border:solid 0px red;"/>';
$(canvas).appendTo("body");
} else {
canvas.css("left", (_point.x - 25) + "px");
canvas.css("top", (_point.y - 25) + "px");
canvas.show();
}
paper = Raphael("canvas");
paper.clear();
var rect = paper.rect(20, 20, 10, 10, 0);
rect.attr("stroke", this.config["rect_color"]);
rect.attr("stroke-width", 1);
}
//是否顯示橫豎條
if (this.config["bar_dis"] == true) {
if (!$("#vline").attr("id")) {
vLine = "<div id='vline' style='background-color:"+this.config["bar_color"]+";height:100%;width:1px;position:absolute;top:0px;left:" + (_point.x) + "px;'/>";
$(vLine).appendTo("body");
} else {
$(vLine).css("left",(_point.x) + "px");
vLine.show();
}
if (!$("#hline").attr("id")) {
var hLine = "<div id='hline' style='overflow:hidden;background-color:"+this.config["bar_color"]+";height:1px;width:100%;position:absolute;left:0px;top:" + (_point.y ) + "px;'/>";
$(hLine).appendTo("body");
} else {
$("#hline").css("top",(_point.y ) + "px");
hLine.show();
}
}
this.hideFocus();
return true;
}, hideFocus:function() {//隱藏焦點(diǎn)效果
if (paper != null) {
var circle = paper.circle(25, 25, 30);
circle.attr("stroke", this.config["circle_color"]);
circle.attr("stroke-width", 1);
var anim = Raphael.animation({
r: 5
}, 900, null, function(){
this.locationTimer = setTimeout(function(){
$("#canvas").hide(); //焦點(diǎn)
$("#vline").hide(); //橫條
$("#hline").hide(); //豎條
clearTimeout(this.locationTimer);
}, 500);
});
circle.animate(anim);
} else {
this.locationTimer = setTimeout(function(){
$("#canvas").hide(); //焦點(diǎn)
$("#vline").hide(); //橫條
$("#hline").hide(); //豎條
clearTimeout(this.locationTimer);
}, 500);
}

},mousePosition:function (e) {
var x,y;
var e = e||window.event;
return {
x:e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,
y:e.clientY+document.body.scrollTop+document.documentElement.scrollTop
}
},elementPosition:function( oElement ) {
var x2 = 0;
var y2 = 0;
var width = oElement.offsetWidth;
var height = oElement.offsetHeight;
var postion = "";
if( typeof( oElement.offsetParent ) != 'undefined' ){
for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
posX += oElement.offsetLeft;
posY += oElement.offsetTop;
}
x2 = posX + width;
y2 = posY + height;
postion = [ posX, posY ,x2, y2];
} else{
x2 = oElement.x + width;
y2 = oElement.y + height;
postion = [ oElement.x, oElement.y, x2, y2];
}
var x = postion[0] + ((postion[2] - postion[0])/2);
var y = postion[1] + ((postion[3] - postion[1])/2);
return {"x":x,"y":y};
}
}

html頁(yè)面調(diào)用源碼:
復(fù)制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/graphics.js"></script>
<script type="text/javascript" src="js/qfocus.js"></script>
<title>qfocus</title>
<script type="text/javascript">
function forward(ev){
qfocus.onmouseClick(ev);
}
document.onmousedown=forward;
</script>
</head>
<body>
</body>
</html>

效果圖片:

相關(guān)文章

最新評(píng)論

兰溪市| 葫芦岛市| 禹州市| 南靖县| 盐城市| 略阳县| 西林县| 阜宁县| 南澳县| 广东省| 南汇区| 枞阳县| 当雄县| 西盟| 九台市| 大丰市| 德惠市| 依兰县| 六盘水市| 淳安县| 中江县| 芒康县| 东山县| 深州市| 策勒县| 台北县| 贵定县| 渭南市| 白朗县| 沾益县| 芒康县| 江山市| 福贡县| 九江县| 兴义市| 泰和县| 华亭县| 澄江县| 颍上县| 天水市| 南宁市|