MMP*_*MMP 1 html javascript jquery
在我的主页上我有这五个div
<table id="nav">
<tr>
<td><a href="coding.html"><div id="pagecl">C O D I N G</div></a></td>
<td><div id="pagecl" class="high">A R T W O R K</div></td>
<td><div id="logo"><img src="imageswebbing/icon.png"></div></td>
<td><a href="extras.html"><div id="pagecl" class="more">E X T R A S</div></a></td>
<td><a href="about.html"><div id="pagecl" class="last">A B O U T</div></a></td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
这是相应的css:
#nav {
margin:300px auto auto auto;
}
#pagecl {
height:40px;
width:200px;
background-color:#151515;
color:white;
text-align:center;
line-height:40px;
opacity:0.7;
font-family: Garamond;
font-size:12px;
}
#logo {
height:120px;
width:120px;
}
Run Code Online (Sandbox Code Playgroud)
并且javascript允许鼠标输入和鼠标离开缓慢淡出,但如果我只在javascript中使用#pagecel id,则只能在第一个"Coding"div上看到预期的效果.这就是我在html和javascript中为其他div添加类选择器的原因.我该如何压缩这个?可能有一个简单的解决方案; 我为成为一名新手而道歉.
$(document).ready(function() {
$('#pagecl').mouseenter(function() {
$(this).fadeTo("slow",1);
});
$('#pagecl').mouseleave(function() {
$(this).fadeTo("slow",.7);
});
$('.high').mouseenter(function() {
$(this).fadeTo("slow",1);
});
$('.high').mouseleave(function() {
$(this).fadeTo("slow",.7);
});
$('.more').mouseenter(function() {
$(this).fadeTo("slow",1);
});
$('.more').mouseleave(function() {
$(this).fadeTo("slow",.7);
});
$('.last').mouseenter(function() {
$(this).fadeTo("slow",1);
});
$('.last').mouseleave(function() {
$(this).fadeTo("slow",.7);
});
});
Run Code Online (Sandbox Code Playgroud)
ID是唯一标识符.根据你的陈述,我有这五个div
<td><a href="coding.html"><div id="pagecl">C O D I N G</div></a></td>
<td><div id="pagecl" class="high">A R T W O R K</div></td>
Run Code Online (Sandbox Code Playgroud)
使它们独一无二,或者你可以用一个类来识别它们
您可以优化您的jQuery代码
使用,通过多个选择.
$(document).ready(function () {
$('#pagecl, .high, .more, .last').hover(function () {
$(this).fadeTo("slow", 1);
}, function () {
$(this).fadeTo("slow", .7);
});
});
Run Code Online (Sandbox Code Playgroud)
也可以使用.hover(),它(selector).hover( handlerIn, handlerOut )是以下的简写:
$( selector ).mouseenter( handlerIn ).mouseleave( handlerOut );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
77 次 |
| 最近记录: |