JavaScript_采用CSS内联样式模拟工具提示;
来源:互联网 发布:淘宝活动抽苹果手机 编辑:程序博客网 时间:2024/06/07 13:01
=>实现功能:采用JS事件驱动以及CSS内联样式模拟工具提示;
<html>
<head><title>使用CSS的工具提示</title>
<script type="text/javascript">
function Tooltip() {
this.tooltip = document.createElement("div");
this.tooltip.style.position = "absolute";
this.tooltip.style.width = "250px";
this.tooltip.style.height = "150px";
this.tooltip.style.backgroundColor = "lightgray";
this.tooltip.style.border = "3px outset black";
this.tooltip.style.visibility = "visible";
this.tooltip.id = "tooltip";
this.tooltip.className = "tooltipShadow";
this.content = document.createElement("div");
this.content.style.position = "relative";
this.content.id = "tipContent";
this.content.className = "tooltipContent";
this.tooltip.appendChild(this.content);
console.log("Tooltip类");
}
Tooltip.prototype.show = function(text, x, y) {
this.content.innerHTML = text;
this.tooltip.style.left = x + "px";
this.tooltip.style.top = y + "px";
this.tooltip.style.visibility = "visible";
if(this.tooltip.parentNode != document.body) {
document.body.appendChild(this.tooltip);
}
console.log("Tooltip show方法");
}
Tooltip.prototype.hide = function() {
this.tooltip.style.visibility = "hidden";
console.log("Tooltip hide方法");
}
function fireFn() {
// 获取用户选择的文本
var text = "";
if(window.getSelection) {
text = window.getSelection().toString();
}else if(document.getSelection) {
text = document.getSelection();
}else if(document.selection) {
text = document.selection.createRange().text;
}
var tip = new Tooltip();
tip.show(text, 100, 100);
setTimeout(function() {
tip.hide();
}, 2000);
}
</script>
</head>
<body>
<p onmouseup="fireFn()">好多即将做软件的或做的时间不长的同仁大多时候关注的是新技术,是创造性;但就和阳光下总有阴影一样,
不管方法如何更迭,总有些东西无法彻底改善。</p>
</body>
</html>
- JavaScript_采用CSS内联样式模拟工具提示;
- 内联式css样式
- css与内联样式
- css与内联样式
- CSS内联样式表用法
- 灵活使用CSS内联样式
- CSS样式中内联、嵌入、外部样式
- CSS:外部样式表/内部样式表/内联样式
- javascript_操作样式
- input通过内联css,改变样式
- CSS样式工具类
- 纯CSS工具提示
- 纯CSS工具提示
- HTML+CSS基础 内联样式表与嵌入样式表设置不同时,听内联的
- CSS Sprites 样式生成工具
- CSS Sprites 样式生成工具
- CSS样式在线生成工具
- css样式内联式,外联式,嵌入式的格式是什么?
- ISO/IEC 14443协议浅谈---TYPE A 与 TYPE B 之比较 (转载)
- opengl中各种坐标的关系的理解
- Linux 内核/sys 文件系统介绍
- Lucene.Net系列学习(3)
- outlook数据文件设置
- JavaScript_采用CSS内联样式模拟工具提示;
- Blackfin BF533 SPI 调试日志
- 旧事重提——行为型设计模式总结一
- make编译文件名非为'makefile'、'Makefile'、'GNUmakefile'时的编译技巧
- jQuery.autocomplete 支持中文输入
- 嵌入式Linux网络驱动程序的开发及实现原理
- Js_基本数据类型
- 《c和指针》笔记
- 数据库设计--ER图