【发布时间】:2014-04-21 18:34:42
【问题描述】:
有没有办法创建一个 JQuery slidedown() 函数,该函数将只分配在鼠标聚焦的 div 上。
这种事情在 JQuery 的组合中是可能的,但我只能做到这一点:只有当每个 div 都有单独的类时,我才能使它工作。如果我将它们命名相同,它将在第一个 div 的悬停时打开(向下滑动)所有 div 标签。
所以,我希望这是一个我看不到的简单解决方案。
我的代码如下:
HTML
<div class="q1">1. Question (on hover)<br/>
<div class="desc1">Description: Here goes the question one from the php variable</div>
<br/></div>
<div class="q2">2. Question (on hover)<br/>
<div class="desc2">Description: Here goes the question two from the php variable</div>
<br/></div>
<div class="q3">3. Question (on hover)<br/>
<div class="desc3">Description: Here goes the question three from the php variable and so on</div>
<br/></div>
JQUERY
jQuery(function () {
for (var i = 0; i < 100; ++i) {
(function (i) {
jQuery('.desc' + i).hide();
jQuery('.q' + i).hover(
function () {
jQuery('.desc' + i, this).stop(true, true).delay(300).slideDown(300);
},
function () {
jQuery('.desc' + i, this).stop(true, true).slideUp(200);
});
}(i));
}});
CSS
.desc1,.desc2,.desc3 {
font-size: 12px;
font-style: italic;
}
.q1,.q2,.q3 {
font-weight:bold;
}
所以,当只有 3 个问题时,这是可行的,但 100 个问题呢?使用我的代码为每个 div 创建 css 将毫无意义,所以我知道有一个简单的解决方案:) :(
【问题讨论】:
标签: javascript jquery css