问题场景:商品描述,当营业员给客户介绍时会看着这些弹出标题来给客户讲解描述,一般采用html中属性title来实现,但是有些商品描述太长,这些title在IE浏览器中大约展示5s,营业员需要多次移动鼠标查看标题 会比较麻烦,原先已经设计商品详情页描述商品详细信息但是营业员不愿意点击看详情页

方案:JS+DIV+CSS  仿造一个title弹出框

难点:CSS对于div位置的控制  不采用事件位置 而是使用position中relative和absolute来确定

谷歌版:

<html>
<head>
<title>鼠标移入显示标题移出标题消失</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.js"></script>
<style>
.tips_show
{
z-index:999;
position:absolute;
/*bottom:10px; 谷歌浏览器要注掉这一行*/
width:auto;
max-width:280px;
overflow:hidden;
padding:0 10px;
border: 1px solid #8797ab;
border-radius:5px;
background:#fff;
white-space:normal;
word-break:normal;
}
.div_show{
display:block;
float:left;
border:1px solid #000;
padding:2px 2px 2px 2px;
}
</style>
<script>
var global_TipsShowId = "";
var global_TipsShowTimer = null;
function showTips(tips,tipsShowDivId,flag)
{
debugger;
if (flag)
{
global_TipsShowId = tipsShowDivId;
global_TipsShowTimer = setTimeout(function(){startShowTipsDiv(tips,tipsShowDivId)},500);
}
else
{
if (tipsShowDivId == global_TipsShowId)
{
global_TipsShowId = "";
var tipsShowDiv = document.getElementById("tips_"+ tipsShowDivId);
if(tipsShowDiv)
{
tipsShowDiv.style.display = "none";
}
if (global_TipsShowTimer)
{
clearTimeout(global_TipsShowTimer);
}
}
}
} function startShowTipsDiv(tips,tipsShowDivId)
{
debugger;
if (global_TipsShowId == tipsShowDivId)
{
if(!tips)
{
tips = $("#"+tipsShowDivId).attr("tips");
}
if (!tips || "" == tips)
{
return;
}
var tips_div_id = "tips_"+ tipsShowDivId;
var tipsShowDiv = document.getElementById(tips_div_id);
if (!tipsShowDiv)
{
$("#"+tipsShowDivId).append("<div id=" +tips_div_id+" class=\"tips_show\" style=\"display:none;\"></div>");
}
tipsShowDiv = document.getElementById(tips_div_id);
tipsShowDiv.innerHTML = "<p style=\"line-height:22px;margin:auto;\">"+tips+"</p>";
tipsShowDiv.style.display = "";
}
}
</script>
</head>
<body>
<div id="div_parent_id_0" style="width:900px;" >
<div id="div_child_0_1" title="商品名称" class="div_show" style="background:red;width:250px;text-align:center;">商品名称</div>
<div id="div_child_0_2" title="商品描述" class="div_show" style="background:red;width:250px;text-align:center;">商品描述</div>
<div id="div_child_0_3" title="商品价格" class="div_show" style="background:red;width:250px;text-align:center;">商品价格</div>
</div>
<div id="div_parent_id_1" style="position:relative;width:900px;">
<div id="div_child_1_1" tips="iPhone 6s" class="div_show" style="width:250px;text-align:center;"
onmouseover="showTips(this.tips,this.id,1)" onmouseout="showTips(this.tips,this.id,0)">iPhone 6s</div>
<div id="div_child_1_2" tips="iPhone 6s是Apple为Apple Watch的上市配备的一款产品" class="div_show" style="width:250px;text-align:left;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"
onmouseover="showTips(this.tips,this.id,1)" onmouseout="showTips(this.tips,this.id,0)">iPhone 6s是Apple为Apple Watch的上市配备的一款产品</div>
<div id="div_child_1_3" tips="¥6480.00元" class="div_show" style="width:250px;text-align:center;"
onmouseover="showTips(this.tips,this.id,1)" onmouseout="showTips(this.tips,this.id,0)">¥6480.00元</div>
</div>
<div id="div_parent_id_2" style="position:relative;width:900px;">
<div id="div_child_2_1" tips="荣耀7" class="div_show" style="width:250px;text-align:center;"
onmouseover="showTips(this.tips,this.id,1)" onmouseout="showTips(this.tips,this.id,0)">荣耀7</div>
<div id="div_child_2_2" tips="华为荣耀7[1-3] 是华为技术有限公司继荣耀6之后,于2015年6月30日在北京工业大学奥林匹克体育馆发布的4G智能手机。" class="div_show" style="width:250px;text-align:left;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"
onmouseover="showTips(this.tips,this.id,1)" onmouseout="showTips(this.tips,this.id,0)">华为荣耀7[1-3] 是华为技术有限公司继荣耀6之后,于2015年6月30日在北京工业大学奥林匹克体育馆发布的4G智能手机。</div>
<div id="div_child_2_3" tips="¥3500.00元" class="div_show" style="width:250px;text-align:center;"
onmouseover="showTips(this.tips,this.id,1)" onmouseout="showTips(this.tips,this.id,0)">¥3500.00元</div>
</div> </body>
</html>

IE8版:

<html>
<head>
<title>鼠标移入显示标题移出标题消失</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.js"></script>
<style>
.tips_show
{
z-index:999;
position:absolute;
bottom:10px;
width:auto;
max-width:280px;
overflow:hidden;
padding:0 10px;
border: 1px solid #8797ab;
border-radius:5px;
background:#fff;
white-space:normal;
word-break:normal;
}
.div_show{
display:block;
float:left;
border:1px solid #000;
padding:2px 2px 2px 2px;
}
</style>
<script>
var global_TipsShowId = "";
var global_TipsShowTimer = null;
function showTips(tips,tipsShowDivId,flag)
{
debugger;
if (flag)
{
//当需要展示的时候将全局ID变量赋值当前所指div id,当移出鼠标时根据是否是当前id来隐藏tips
//且0.5s后根据全局变量是否被改变来确定是否要继续展示tips
global_TipsShowId = tipsShowDivId;
global_TipsShowTimer = setTimeout(function(){startShowTipsDiv(tips,tipsShowDivId)},500);
}
else
{
if (tipsShowDivId == global_TipsShowId)
{
global_TipsShowId = "";
var tipsShowDiv = document.getElementById("tips_"+ tipsShowDivId);
if(tipsShowDiv)
{
tipsShowDiv.style.display = "none";
}
if (global_TipsShowTimer)
{
clearTimeout(global_TipsShowTimer);
}
}
}
} function startShowTipsDiv(tips,tipsShowDivId)
{
debugger;
if (global_TipsShowId == tipsShowDivId)
{
//谷歌浏览器不支持this.tips传参
if(!tips)
{
tips = $("#"+tipsShowDivId).attr("tips");
}
//没有tips则不展示直接返回
if (!tips || "" == tips)
{
return;
}
//判断是否已创建 防止再次创建
var tips_div_id = "tips_"+ tipsShowDivId;
var tipsShowDiv = document.getElementById(tips_div_id);
if (!tipsShowDiv)
{
$("#"+tipsShowDivId).append("<div id=" +tips_div_id+" class=\"tips_show\" style=\"display:none;\"></div>");
}
tipsShowDiv = document.getElementById(tips_div_id);
tipsShowDiv.innerHTML = "<p style=\"line-height:22px;margin:1px 2px;\">"+tips+"</p>";
tipsShowDiv.style.display = "";
}
}
</script>
</head>
<body>
<div id="div_parent_id_0" style="width:900px;" >
<div id="div_child_0_1" title="商品名称" class="div_show" style="background:red;width:250px;text-align:center;">商品名称</div>
<div id="div_child_0_2" title="商品描述" class="div_show" style="background:red;width:250px;text-align:center;">商品描述</div>
<div id="div_child_0_3" title="商品价格" class="div_show" style="background:red;width:250px;text-align:center;">商品价格</div>
</div>
<div id="div_parent_id_1" style="position:relative;width:900px;">
<div id="div_child_1_1" tips="iPhone 6s" class="div_show" style="width:250px;text-align:center;"
onmouseover="showTips(this.tips,this.id,1)" onmouseout="showTips(this.tips,this.id,0)">iPhone 6s</div>
<div id="div_child_1_2" tips="iPhone 6s是Apple为Apple Watch的上市配备的一款产品" class="div_show"
onmouseover="showTips(this.tips,this.id,1)" onmouseout="showTips(this.tips,this.id,0)">
<p style="width:242px;text-align:left;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">iPhone 6s是Apple为Apple Watch的上市配备的一款产品</p> </div>
<div id="div_child_1_3" tips="¥6480.00元" class="div_show" style="width:250px;text-align:center;"
onmouseover="showTips(this.tips,this.id,1)" onmouseout="showTips(this.tips,this.id,0)">¥6480.00元</div>
</div>
<div id="div_parent_id_2" style="position:relative;width:900px;">
<div id="div_child_2_1" tips="荣耀7" class="div_show" style="width:250px;text-align:center;"
onmouseover="showTips(this.tips,this.id,1)" onmouseout="showTips(this.tips,this.id,0)">荣耀7</div>
<div id="div_child_2_2" tips="华为荣耀7[1-3] 是华为技术有限公司继荣耀6之后,于2015年6月30日在北京工业大学奥林匹克体育馆发布的4G智能手机。" class="div_show"
onmouseover="showTips(this.tips,this.id,1)" onmouseout="showTips(this.tips,this.id,0)">
<p style="width:242px;text-align:left;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">华为荣耀7[1-3] 是华为技术有限公司继荣耀6之后,于2015年6月30日在北京工业大学奥林匹克体育馆发布的4G智能手机。</p>
</div>
<div id="div_child_2_3" tips="¥3500.00元" class="div_show" style="width:250px;text-align:center;"
onmouseover="showTips(this.tips,this.id,1)" onmouseout="showTips(this.tips,this.id,0)">¥3500.00元</div>
</div> </body>
</html>

注:IE下的样式有待调整。

参考:

鼠标放上显示跟随鼠标的提示文字信息

js特效-仿照html属性title写一个弹出标题样式的更多相关文章

  1. vue.js 利用组件之间通讯,写一个弹出框例子

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 创建一个弹出DIV窗口

    创建一个弹出DIV窗口 摘自:   http://www.cnblogs.com/TivonStone/archive/2012/03/20/2407919.html 创建一个弹出DIV窗口可能是现在 ...

  3. 仿腾讯微博的一个弹出框 v0.1 beta

    仿腾讯微博的一个弹出框 v0.1 beta   代码写的不太好,新手请大家海涵,只为博君一笑,勿放在心上. 写在这里留作纪念,也许以后用的到. 效果 CSS .prompt{ position: ab ...

  4. 利用React/anu编写一个弹出层

    本文将一步步介绍如何使用React或anu创建 一个弹出层. React时代,代码都是要经过编译的,我们很多时间都耗在babel与webpack上.因此本文也介绍如何玩webpack与babel. 我 ...

  5. android一个弹出菜单的动画(二)

    假设做一个弹出的控件,我们能够进行加入view: 写class SatelliteMenu extends FrameLayout private void init(Context context, ...

  6. Bootstrap方法为页面添加一个弹出框

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. 点击图片或者鼠标放上hover .图片变大. 1)可以使用css中的transition, transform 2) 预先设置一个 弹出div. 3)弹出层 alert ; 4) 浏览器的宽度document.documentElement.clientWidth || document.body.clientWidth

    变大: 方法一: 利用css属性. 鼠标放上 hover放大几倍. .kecheng_02_cell_content img { /*width: 100px; height: 133px;*/ wi ...

  8. 使用node.js 文档里的方法写一个web服务器

    刚刚看了node.js文档里的一个小例子,就是用 node.js 写一个web服务器的小例子 上代码 (*^▽^*) //helloworld.js// 使用node.js写一个服务器 const h ...

  9. Vue.js 3.0搭配.NET Core写一个牛B的文件上传组件

    在开发Web应用程序中,文件上传是经常用到的一个功能. 在Jquery时代,做上传功能,一般找jQuery插件就够了,很少有人去探究上传文件插件到底是怎么做的. 简单列一下我们要做的技术点和功能点 使 ...

随机推荐

  1. MariaDB10.2.X-新特性1-支持分析函数

    前言:前段时间看到MariaDB10.2出测试版本了,心想有什么新特性玩玩,大家都知道MySQL不支持分析函数,但是MariaDB10.2.X支持分析函数了, 1.表结构 CREATE TABLE ` ...

  2. RecyclerView(6)自定义RecyclerView.LayoutManager

    A LayoutManager is responsible for measuring and positioning item views within a RecyclerView as wel ...

  3. Apache httpd + tomcat 简单集群

    集群其实很简单,我们就来说一下httpd+tomcat集群都要注意哪些部分: 首先使用的东西有 apache-tomcat-8.0.32      下载地址: http://tomcat.apache ...

  4. Jeally Bean中MonekyRunner 帮助文件

    基于4.2的SDK导出来的MonkeyRunner的最新帮助,这个版本对MonkeyView和MonkeyRect有了很大的加强,在MonkeyRunner的易用性上有了很大的提高. 对于导出Monk ...

  5. bzoj2823

    最小圆覆盖 有个东西叫作随机增量法,具体可以baidu 这里来说说怎么求三点共圆 这其实就是求两条线段的交点 在编程中,我们解方程是比较麻烦的一个比较好的方法是利用相似三角形 设线段AB,CD交P,则 ...

  6. apache开源项目-- Turbine

    1.缘起 Jetspeed是Apache Jakarta小组的开放源码门户系统.它使得最终用户可以通过WAP手机.浏览器.PDA等各种设备来使用各种各样的网络资源(比如应用程序.数据以及这之外的任何网 ...

  7. 【转】如何在eclipse里关联查看android源码

    原文网址:http://fengbohaishang.blog.51cto.com/5106297/1339556 以前没怎么注意过这个问题,不怎么看源码,现在发现源码确实是很好的学习资源. 直入正题 ...

  8. linux中waitpid及wait的用法

    wait(等待子进程中断或结束) 表头文件      #include<sys/types.h>      #include<sys/wait.h> 定义函数 pid_t wa ...

  9. MyBatis的association示例——MyBatis学习笔记之三

    前两篇博文介绍的都是单表映射,而实际上很多时候我们需要用到较复杂的映射.今天学会的association的用法,就是一例,现写出来和大家分享(为简洁起见,ant工程中各文件.目录的布局,以及其它与前面 ...

  10. Kafka 设计与原理详解

    一.Kafka简介 本文综合了我之前写的kafka相关文章,可作为一个全面了解学习kafka的培训学习资料. 转载请注明出处 : 本文链接 1.1 背景历史 当今社会各种应用系统诸如商业.社交.搜索. ...