jQuery:如何淡出不常用的 div 列表,并在鼠标悬停时淡入?

发布于 2024-08-19 08:59:01 字数 68 浏览 3 评论 0原文

假设您在网页上有一堆不常使用的元素,jQuery 如何使它们稍微淡化一点,但只有在没有鼠标悬停时?它必须在鼠标悬停时淡出!

Say you have a bunch of elements on a webpage you don't use much, how can jQuery fade them a little, but only when there is no mouseover? It must fade back on mouseover!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

单身狗的梦 2024-08-26 08:59:01

我是这样解决的:

//list the items you want to fade out in normal selector format
var arr = [ "#navTop","#banner","#idViewToolbar","#fbsidebar","#idActionP","table.noBorder" ];


//delay function by Clint Helfers
$.fn.delay = function( time, name ) {

    return this.queue( ( name || "fx" ), function() {
        var self = this;
        setTimeout(function() { $.dequeue(self); } , time );
    } );

};

$.each( arr, function(i, l){
   jQuery(l).fadeTo(600, 0.10);
   jQuery(l).mouseenter(function(){
        jQuery(this).fadeTo(600, 1);
    });

       jQuery(l).mouseleave(function(){
        jQuery(this).delay(5000).fadeTo(600, 0.10);
    });

 });

我实际上将它用于 FogBugz - 他们有一个插件,可以让你将自己的 CSS + Javascript 插入到页面中,我用它来淡出大多数内容,但我正在处理的错误/功能列表。

I solved it like this:

//list the items you want to fade out in normal selector format
var arr = [ "#navTop","#banner","#idViewToolbar","#fbsidebar","#idActionP","table.noBorder" ];


//delay function by Clint Helfers
$.fn.delay = function( time, name ) {

    return this.queue( ( name || "fx" ), function() {
        var self = this;
        setTimeout(function() { $.dequeue(self); } , time );
    } );

};

$.each( arr, function(i, l){
   jQuery(l).fadeTo(600, 0.10);
   jQuery(l).mouseenter(function(){
        jQuery(this).fadeTo(600, 1);
    });

       jQuery(l).mouseleave(function(){
        jQuery(this).delay(5000).fadeTo(600, 0.10);
    });

 });

I actually used it for FogBugz - they have a plugin that lets you insert your own CSS + Javascript into the page, I use it to fade out most stuff but the bug/feature list I'm working on.

<逆流佳人身旁 2024-08-26 08:59:01

如果您不需要动画内容,您可以使用 :hover psoudo 选择器使用纯 css 来完成此操作,但是 jquery 中还有一个 .hover() 方法,它会帮助你达到这个效果。像这样的东西: $('.my_less_used_divs').hover(fadeInFunction, fadeOutFunction);

if you dont need the animation stuff you can do this with pure css by using the :hover psoudo selector however there is also a .hover() method in jquery, it will help you to achieve this effect. something like this: $('.my_less_used_divs').hover(fadeInFunction, fadeOutFunction);

挽心 2024-08-26 08:59:01

将 antpaw 推荐的内容实际放入代码中。执行以下操作。

$(".my_less_used_divs").hover(function() {
    $(this).css("opacity", 1);
}, function() {
    $(this).css("opacity", .5);
}).css("opacity", .5);

如果你喜欢这个,你应该给 antpaw 接受的答案。

To actually put what antpaw recommended into code. Do the following.

$(".my_less_used_divs").hover(function() {
    $(this).css("opacity", 1);
}, function() {
    $(this).css("opacity", .5);
}).css("opacity", .5);

You should give antpaw the accepted answer if you like this.

凉世弥音 2024-08-26 08:59:01
$(".divfade").hover(function() {
    $(this).fadeTo("slow", 1);
}, function() {
    $(this).fadeTo("slow" , .5);
}).css("opacity", .5);

此代码确实淡入和淡出。

$(".divfade").hover(function() {
    $(this).fadeTo("slow", 1);
}, function() {
    $(this).fadeTo("slow" , .5);
}).css("opacity", .5);

This code does fade in and fade out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文