English 中文(简体)
better way of jquery mouseover?
原标题:

I am trying to create an effect where if you hover over an img, the color of text will change below it. And also, when you mouseout, the color will change back to its original color. The page is: http://vitaminjdesign.com/work.html

My code is:

    if(window.jQuery){jQuery(function(){

        (function(){ jQuery( div#one img ).bind( mouseover , function(event, ui){var target = jQuery( div#one h2 ); target.animate({ color : #111111 },250, linear )});})();

    })};

I repeated this about 15 times in a page, and it seems to be pretty buggy, and not smooth. Playt around with it for a minute. Is there a better way of going about this?

最佳回答

Try using hover, the benefit being that you can specify the mousein and mouseout events in the same function. If you need any help with specifically how to apply what you ve got to the hover event, just comment and I ll see what I can do.

EDIT:

Ok, the code on your site already has this

//On mouse over those thumbnail
$( .zitem ).hover(function() {

    //Set the width and height according to the zoom percentage
    width = $( .zitem ).width() * zoom;
    height = $( .zitem ).height() * zoom;

    //Move and zoom the image
    $(this).find( a img ).stop(false,true).animate({ width :width,  height :height,  top :move,  left :move}, {duration:200});

    //Display the caption
    $(this).find( div.caption ).stop(false,true).fadeIn(200);
},
function() {
    //Reset the image
    $(this).find( a img ).stop(false,true).animate({ width :$( .zitem ).width(),  height :$( .zitem ).height(),  top : 0 ,  left : 0 }, {duration:100});    

    //Hide the caption
    $(this).find( div.caption ).stop(false,true).fadeOut(200);
});

I m going to add two lines into this code that do what you want

//On mouse over those thumbnail
$( .zitem ).hover(function() {

    //Set the width and height according to the zoom percentage
    width = $( .zitem ).width() * zoom;
    height = $( .zitem ).height() * zoom;

    //Move and zoom the image
    $(this).find( a img ).stop(false,true).animate({ width :width,  height :height,  top :move,  left :move}, {duration:200});

    //Change the header colour
    $(this).siblings( h2 ).animate({ color : #111111 },250, linear );

    //Display the caption
    $(this).find( div.caption ).stop(false,true).fadeIn(200);
},
function() {
    //Reset the image
    $(this).find( a img ).stop(false,true).animate({ width :$( .zitem ).width(),  height :$( .zitem ).height(),  top : 0 ,  left : 0 }, {duration:100});    

    //Change the header colour back
    $(this).siblings( h2 ).animate({ color : #EE4E07 },250, linear );

    //Hide the caption
    $(this).find( div.caption ).stop(false,true).fadeOut(200);
});

That should do it

问题回答

暂无回答




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签