jQuery(document).ready(function(){
$(function() {
$('.button-a').each(function() {
$(this).hover(
function () {
$('.button-title', this).animate({ opacity: 0.6 }, 200);
});
});
});
$(function() {
$('.button-b').each(function() {
$(this).hover(
function () {
$('.button-title', this).animate({ opacity: 0.6 }, 200);
});
});
});
$(function() {
$('.button-c').each(function() {
$(this).hover(
function () {
$('.button-title', this).animate({ opacity: 0.6 }, 200);
});
});
});
$(function() {
$('.button-d').each(function() {
$(this).hover(
function () {
$('.button-title', this).animate({ opacity: 0.6 }, 200);
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
我有很多按钮,当悬停每个按钮时,会有一些不透明度的变化.
代码类似,小不一样$('.button-a'),$('.button-b'),$('.button-c'),$('.button-d'),是否可以结合jquery各个功能?这样我可以缩短我的代码?谢谢.
您可以使用multiple-selector[docs].
$(function() {
$('.button-a,.button-b,.button-c,.button-d').hover(function () {
$('.button-title', this).animate({ opacity: 0.6 }, 200);
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
631 次 |
| 最近记录: |