开发者

Jquery captions on Hover

I've written a simple script in jQuery that allows a caption to pop in and out based on the .hover trigger.

The problem is that you have to hover over the image, move back out then hover over it again before it works. (you can see what I mean here http://jsfiddle.net/sambeckhamdesign/bqjqb/)

Is it a problem with the (document).ready() part or just a glitch in jQuery itself? I really can't see the problem here, seems too simple to mess up lol.

开发者_开发问答
jQuery(document).ready(function() {
$(".projectImages li").hover(

function() {
    $(this).find(".imageCaption").animate({
        opacity: "show",
        bottom: "0"
    }, "fast");
},

function() {
    $(this).find(".imageCaption").animate({
        opacity: "hide",
        bottom: "-50"
    }, "fast");
});
});


Adjust your image caption class to display:none;. Changing that should define the element in the correct state for the first hover.

.imageCaption{
    display:none;
    position:absolute;
    background:#f0f;
    bottom:-50px;
    width:100%;
    color:#fff;
}

Since your initial state of the element was block the mouse enter never was executed since it was already set to block..

Updated jsfiddle


Try:

jQuery(document).ready(function() {
$(".projectImages li").hover(


    $(this).find(".imageCaption").animate({
        opacity: "show",
        bottom: "0"
    }, "fast").animate({
        opacity: "hide",
        bottom: "-50"
    }, "fast");
});


Use jQuery to hide element on page load :

http://jsfiddle.net/FrelCee/bqjqb/33/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜