码迷,mamicode.com
首页 > Web开发 > 详细

JQuery实现文本放大效果

时间:2015-04-29 21:52:43      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:jquery   javascript   放大   

html页面
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
*{
margin:0px;
padding:0px;
}
</style>
<script src="jquery-1.11.1.js"></script>
<script src="bigshow.js"></script>
<script>
$(function(){
$("#info").bigShow([3,3,4,4,4]);
})
</script>
</head>
<body>
<br/><br/>
&nbsp;&nbsp;&nbsp;&nbsp;需要放大的内容<input type="text" id="info"/>
</body>
</html>

JQuery代码
// JavaScript Document
$.fn.bigShow=function(num){ //给定多少一个空格,可以是一个数字也可以是一个数组
var info=$(this);//传来的text对象
var bigT=$("<p id=‘bigShow‘></p>");//获取放大框对象
info.after(bigT);//增加标签
bigT.css({position:"absolute",height:"25px",border:"1px solid #F93",color:"red",display:"none",padding:"4px","line-height":"25px","font-size":"28px","border-radius":"2px","font-weight":"bold"});//设置放大框样式

var tops;//放大框距顶部的距离
if(info.offset().top<50){//放大框在下方显示
tops=info.offset().top+info.height()+10;
}else{
tops=info.offset().top-bigT.height()-16;
}
info.keyup(function(){
var widths=info.offset().left+info.width()/2-bigT.width()/2;//放大框距左边的距离
bigT.css({top:tops,left:widths});//设置位置
var str="";
var vals=$(this).val();
if(typeof(num)=="object"){
var index=0;
for(var i=0;i<num.length;i++){
if(i==0){
str+=vals.substr(index,num[i])+" ";
}else{
str+=vals.substr(index,num[i])+" ";
}
index+=num[i];
}
}else{
for(var i=0;i<vals.length;i+=4){
str+=vals.substr(i,4)+" ";
}
}
bigT.text(str);//实时赋值
});
info.blur(function(){
bigT.css("display","none");
});
info.focus(function(){
bigT.css("display","block");
var widths=info.offset().left+info.width()/2-bigT.width()/2;
bigT.css({top:tops,left:widths});
});
}
技术分享

JQuery实现文本放大效果

标签:jquery   javascript   放大   

原文地址:http://blog.csdn.net/qfxsxhfy/article/details/45370103

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!