English 中文(简体)
Using Jquery for mouseover effect and queue
原标题:

I ve been looking around for the last couple hours on how to do this - can t find it anywhere.

I have several buttons (divs). It consists of a div within a div. The parent div has the normal button background image, the child has a lighter glowy background image. On Mouseover, I want the child div to go to an opacity of 1.0, then fade out to 0.2 (so it looks like a flash). On MouseOut, it just needs to go back to 0.0. Obviously I don t want MouseOver/MouseOut queue buildup.

I looked at queue effects, but I can t figure out how to get this to work with a MouseOver button. Plus I suck at JS.

最佳回答

You should use mouseenter and mouseleave. The mouseover and mouseout events fire continuously as the cursor is moved inside of an element.

$(".button")
    .mouseenter(function() {
        var overlay = $("div:first",this).fadeTo(350, 1.0, function() {
            overlay.fadeTo(350, 0.2);
        });
    })
    .mouseleave(function() {
        $("div:first", this).stop().fadeOut(350);
    });
问题回答

Did you have a look at the fadeTo method? http://jquery.bassistance.de/api-browser/#fadeToStringNumberNumberFunction

It should be something like this (haven t tested it, though)

var childdiv = $("#childdiv");
childdiv .fadeTo(500, 1.0, function(){ 
  childdiv .fadeTo(500, 0.2);
});

The problem is Hover has a function as well, and I think I am getting confused...

address the div called ButtonBGanim:

$(document).ready(function(){

var buttonbg = $("#ButtonBGanim");

$(buttonbg).hover(
function() {
$(this).stop().fadeTo(500, 1.0, function(){ 
  buttonbg .fadeTo(500, 0.2);
},
function() {
$(this).stop().fadeTo(500, 0.0)
});

untested but should be pretty close.

$("#id").hover(
      function () {
    $(this).stop().children("div").fadeTo("fast", 1.0).fadeTo("slow", 0.2);
      }, 
      function () {
        $(this).stop().children("div").fadeTo("slow", 0.0);
      }
    );




相关问题
c# stack queue combination

is there in C# some already defined generic container which can be used as Stack and as Queue at the same time? I just want to be able to append elements either to the end, or to the front of the ...

Packet Queue in Python?

is there any way to queue packets to a socket in Python? I ve been looking for something like the libipq library, but can t find anything equivalent. Here s what I m trying to accomplish: Create ...

Java Queue Merge, Beginner

I m trying to write a method that will take in two Queues (pre-sorted Linked Lists) and return the merged, in ascending order, resulting Queue object. I pasted the Queue class, the merge method ...

Efficient queue in Haskell

How can I efficiently implement a list data structure where I can have 2 views to the head and end of the list, that always point to a head a tail of a list without expensive calls to reverse. i.e: ...

Thread & Queue vs Serial performance

I though it ll be interesting to look at threads and queues, so I ve written 2 scripts, one will break a file up and encrypt each chunk in a thread, the other will do it serially. I m still very new ...

Insert into an STL queue using std::copy

I d like to use std::copy to insert elements into a queue like this: vector<int> v; v.push_back( 1 ); v.push_back( 2 ); queue<int> q; copy( v.begin(), v.end(), insert_iterator< queue&...

Threading in Ruby with a limit

I have a task I need to perform, do_stuff(opts), that will take ~1s each, even while 1 - 10 of them are running in parallel. I need to collect an array of the results for each operation at the end. ...

热门标签