Due to a bit of confusion with the interpretation of the problem, here are three answers for three separate problems, the last one being the correct one.
Method One
Here, the guitar is rolled up to the top and then subsequently pulled back down, like blinds on a window. The third argument for effect()
and other functions such as toggle()
is a callback.
$('div').on('click', function(){
$(this).toggle( "blind", {direction: "up"}, function(){
$(this).toggle( "blind", {direction: "up"});
});
})
Direction "up" is default, so this might be even simpler:
$('div').on('click', function(){
$(this).toggle( "blind", function(){
$(this).toggle("blind");
});
})
Method Two
Here, we squeeze the image until it disappears. We use JQuery UI's clip along with some CSS changes:
JQuery
$('div').on('click', function(){
$(this).hide('clip', {direction: 'vertical'}, 1000);
});
CSS
div {
position: relative;
}
div img {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
}
By adding this css, the image height will always expand to the div's edges. Adding the JQuery UI clip to the div, the img overflow will therefore not be chopped off and be instead resized in the correct way.
Method Three
I think this is the intended effect you would like. The image remains fixed while the top and bottom are clipped, just like having JQuery blind being simultaneously executed as specified by the prompt. We may implement this using clip + CSS3.
JQuery
$('img').on('click', function(){
$(this).css('clip', "rect(50px 75px 50px 0)");
})
CSS
div {
position: relative;
}
div img {
position: absolute;
height: 100px;
width: 75px;
clip: rect(0 75px 100px 0);
-webkit-transition: clip 2s;
transition: clip 2s;
}
Note that the CSS clip
must be used on an absolutely positioned element. We start with a rectangle that contains the entire image. We then clip it so that the rectangle has zero height. We smooth out this process by using CSS3 transitions.