firefox中boundingWidth以及boundingHeight的获取
来源:互联网 发布:带雨带知的俗语 编辑:程序博客网 时间:2024/05/22 17:40
这几天在做兼容,所以遇到的怪问题比较多,记录一下。
boundingWidth以及boundingHeight是结合createTextRange来进行使用的。
例如:
在这里我们希望得到Input里面value的宽度和高度。在IE里面就可以使用boundingWidth以及boundingHeight直接得到。
但是这两个方法只有IE支持,在firefox中我们可以采用下面这种折中的办法来进行解决。
var inputId = elem.attributes["id"].nodeValue;//input的idvar parentDiv = $('<div></div>');//创建divparentDiv.attr('id','parentId');//设置idparentDiv.appendTo('body');//将div加入页面parentDiv.css("display","inline-block").hide();var a = $("#"+inputId).val();$("#parentId").html(a);//将输入框的内容加入divvar r,x,y,l,t,w,h;if(navigator.userAgent.indexOf("MSIE")<=0){x = event.layerX;//鼠标当前坐标//y = event.layerY;//l = $("#"+inputId).offset().left;//t = $("#"+inputId).offset().top;w = $("#parentId").width();//h = $("#parentId").height();//w = $("#"+id)[0].offsetWidth;//h =$("#"+id)[0].offsetHeight;//w = $("#"+id).width();//input的宽度//h = $("#"+id).height();//input的高度if(x>w){return false;}else{return true;}}else{r = elem.createTextRange();x = event.offsetX;//鼠标当前坐标y = event.offsetY;l = r.offsetLeft;t = r.offsetTop;w = r.boundingWidth;h = r.boundingHeight;}var c =x >= l && x < l + w && y >= t && y < t + h;return c;
我们可以先获取到input的value,然后定义一个div,将value放入其中,然后得到div的宽度和高度,经过检测,支持firefox和google。
如果你有更好的办法,请分享一下,非常感谢!
0 0
- firefox中boundingWidth以及boundingHeight的获取
- Firefox插件中invoke方法获取参数以及参数转化
- Firefox插件中invoke方法获取参数以及参数转化
- Firefox中获取Attribute的问题
- 短信验证倒计时以及在firefox中出现的问题
- 在firefox中获取网页里的SWF对象
- 在firefox中获取网页里的SWF对象
- ajax中获取XMLHttpRequest对象的方法(IE/Firefox/chrome)
- Firefox中元素获取焦点函数focus不起作用的解决方法
- javascript获取光标位置以及设置光标位置(兼容firefox)
- firefox获取事件源以及swapNode兼容处理
- 在firefox的extension(chrome)中获取当前页面的属性或方法
- Firefox的卸载与安装以及升级
- 下载firebug以及设置firefox的语言.
- python 获取firefox下的https信息
- Firefox中console的用法
- Firefox最常用的键盘快捷键的列表以及它们在IE和 Opera中相对应的快捷键
- Java中获取进程ID以及杀死进程的方法
- VA release notes (zz)
- 分享操作分类信息上网进行网站推广的法子
- 分享成为SEO高手的九大技巧
- Linux 隐藏文件和隐藏文件夹
- 黑马程序员_异常
- firefox中boundingWidth以及boundingHeight的获取
- Android Tab 的使用
- 分享处所团购上网从建站到推广经验
- 分享从实战的角度去分析seo的必要
- c++builder与matlab混合编程mInitialize错误原因
- vlc 录制 stream方法
- provider:Named Pipes Provider,error:40 - 无法打开SQL Server的连接
- v4l2图像数据采集 x264笔记
- 分享的HTML标签在SEO中的分值