开发者

Jquery click and toggleClass question

开发者 https://www.devze.com 2023-01-24 04:50 出处:网络
here\'s my probably (and hopefully) simple problem: i have a list with images as navigation. when you hover over them, jquery animates a div with a caption and shows it. it disapears on mouseout. (wo

here's my probably (and hopefully) simple problem:

i have a list with images as navigation. when you hover over them, jquery animates a div with a caption and shows it. it disapears on mouseout. (works fine)

when you click on the image, the caption div animates further and is overlaying the image completly (works fine). while hovering over another image in the nav the caption div animates aswell (works fine).

the problem: when clicking a second navigation image, the animation of the first one(clicked) sho开发者_JAVA技巧uld disapear.

here's the jquery:

var thumbslide = $('.boxgrid.captionfull').click(function() {
   $(this).toggleClass('clicked').children('.cover').stop().animate({top: 0, height:"230px", opacity: 1}, 350);
});
$('.boxgrid.captionfull:not(.clicked)').live('mouseenter', function() {
    $(this).children('.cover').stop().animate({top: 130}, 350);
}).live('mouseleave', function() {
    $(this).children('.cover').stop().animate({top: 230}, 350);
})

and here's a link to the dev site

any help is welcome, thanks.


This removes the clicked class and animates it back down and returns the opacity back to 0.7:

var thumbslide = $('.boxgrid.captionfull').click(function() {
   $('.boxgrid.captionfull.clicked').removeClass('clicked').children('.cover').stop().animate({top: 230, opacity: 0.7}, 350);
   $(this).toggleClass('clicked').children('.cover').stop().animate({top: 0, height:"230px", opacity: 1}, 350);
});


Isnt this just a case of finding any other clicked item and removing its clicked class?

var thumbslide = $('.boxgrid.captionfull').click(function() {
   $('.boxgrid.captionfull.clicked').removeClass('clicked');
   $(this).toggleClass('clicked').children('.cover').stop().animate({top: 0, height:"230px", opacity: 1}, 350);
});
0

精彩评论

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