将鼠标悬停更改为单击

时间:2013-12-03 21:41:25

标签: html css

我最近创建了一个按钮,当用户滚动按钮时,该按钮显示带有文本的黑色弹出框(在按钮本身之外)。我希望在单击按钮时显示该框而不是悬停在框上,并且一旦用户再次单击该按钮,框就会消失。我被告知这不能用CSS完成,我将不得不使用JavaScript。请求帮助。谢谢!下面是按钮当前如何工作的小提琴链接。 http://jsfiddle.net/44hx4/2/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0016)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Theory of Operation</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
td img {display: block;}body {
    margin-left: 0px;
    margin-top: 0px;
}

a:link {text-decoration: none;}
a:visited {text-decoration: none;}
a:visited {color:#0000FF;}
a:hover {text-decoration: underline;}
a:active {text-decoration: underline;}

body {
  font: 16px/1.4 arial;
  background-color: #7D8859;
}




body {
  font: 16px/1.4 arial;
  background-color: #7D8859;
}

.imgWrap {
  position: absolute;
  height: 76px;
  width: 50px;
  top: 556px;
}

.imgDescription {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.80);
  color: #fff;
  margin: -500px -340px 85px 50px;
  padding: 10px;
  z-index:10;


  visibility: hidden;
  opacity: 0;

  /*remove comment if you want a gradual transition between states
  -webkit-transition: visibility opacity 0.2s;
  */
}


.imgWrap:hover .imgDescription {
  visibility: visible;
  opacity: 1;
}



</style>
<script src="../javascript/swfobject_modified.js" type="text/javascript"></script><script language="JavaScript1.2" type="text/javascript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_popupMsg(msg) { //v1.0
  alert(msg);
}


//-->
</script>
<script language="javascript" src="../javascript/configure.js" type="text/javascript"></script>
<script language="javascript" src="../javascript/scorm.js" type="text/javascript"></script>
<script language="javascript" src="../javascript/lms.js" type="text/javascript"></script>
<script language="Javascript" src="../javascript/common.js" type="text/javascript"></script>
<script language="Javascript" src="../javascript/common2.js" type="text/javascript"></script>

<script type="text/javascript">

function popup(){
  cuteLittleWindow = window.open("hey", "littleWindow", "location=no,width=320,height=200"); 
}

</script>



<link href="../css/style.css" rel="stylesheet" type="text/css" />
</head>
<body bgcolor="#ffffff" onload="MM_preloadImages('images/2-3_A.jpg','images/Module 3/3-0_A.jpg','images/Module 3/3-0_B.jpg','images/Module 3/3-0_E.jpg','images/Module 3/3-0_F.jpg','images/Module 3/3-2-1-7.jpg','images/Module 3/3-6-1a-5.jpg','images/Module 3/3-6-1a-2.jpg','images/Module 3/3-6-1a-1.jpg','images/module 4/4-2_A.jpg','interface/text_2.jpg')">
<table style="display: inline-table;" border="0" cellpadding="0" cellspacing="0" width="800" height="600">
  <tr>
    <td><table style="display: inline-table;" align=""left" border="0" cellpadding="0" cellspacing="0" width="800">
      <tr>        </tr>
    </table>
    </td>
  </tr>
  <tr>      

  <td>&nbsp;</td>
  </tr>  
  <tr>
   <td><table style="display: inline-table;" align=""left" border="0" cellpadding="0" cellspacing="0" width="800">
      <tr>
        <td><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image10','','interface/text_2.jpg',1)">



          <div class="imgWrap"><img src="interface/text_1.jpg" name="Image10" width="76" height="50" border="0" id="Image10" />
            <p class="imgDescription">

             HELLO! 


              </p>



</div></a><a href="m02_3.html" onmouseout="MM_swapImgRestore();" onmouseover="MM_swapImage('mircs_interface_r4_c15_s1','','../share/images/interface/mircs_interface_r4_c15_s2.jpg',1)"></a></td>
        </tr>
    </table></td>
  </tr>
</table>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您可以尝试使用jQuery,例如Fiddle

$(function(){
    $("#Image10").click(function(){
        $(".imgDescription").toggleClass("show");
    });
});

虽然我个人会改为切换显示而不是像Fiddle

那样的可见性