【发布时间】:2015-02-16 09:23:22
【问题描述】:
我是学习 jquery 和制作自己的网站的新手。这是我的小提琴 JSFIDDLE。当您将鼠标悬停时,一个新的 div 会显示一些文本。但是文本会从那个 div 中消失。我想要新 div 中的文本。我不知道为什么会这样。我知道这是一个愚蠢的问题,但我花了一个多小时才把它弄好。
代码
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="example.js"></script>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="box">
<h2 id='name'> Karan Shah </h2>
<div id='innerbox'><span><h4 id='emptyInfo'></h4></span><div>
<script>
$('#innerbox').hide();
</script>
</div>
<script>
$('#name').css('color','black');
$('#name').css('text-align','center');
$(document).ready(function () {
var originalText = $('#name').text();
var tOut;
$("#box").hover(
function () {
tOut = setTimeout(function(){
$('#innerbox').show('slow',function(){
$('#emptyInfo').fadeOut(400, function () {
$(this).text('Welcome to my website').slideDown().css('text-align','center');
});
});
},1000);
},
function(){
clearTimeout(tOut);
$('#innerbox').hide('slow',function(){
$('#emptyInfo').hide('slow');
});
}
);
});
</script>
</body>
</html>
CSS
#box {
background-color: lightgrey;
width: auto;
padding: 25px;
margin: 25px;
}
#emptyInfo{
font-size: 150%;
}
#innerbox {
background-color: white;
width: auto;
height: 30px;
border-radius: 10px;
border : 1px;
border-style: solid;
border-color: darkgrey;
}
【问题讨论】:
-
你必须重置默认
<h4>边距:#emptyInfo { margin: 0; }。 -
哇。这有帮助。非常感谢。我觉得花这么多时间在这件小事上太愚蠢了。再次感谢
标签: javascript jquery html css