Skip to content Skip to sidebar Skip to footer

Jquery / Jquery Tools Getting Smaller Effect

I want to develop a screen with JQuery Tools(or just with JQuery) and HTML5. There will be a main panel at screen and it will have rounded square buttons on it. When user clicks a

Solution 1:

See demo

The following will work for Chrome, Safari, FF 4+ and Opera 10+. The magic is in CSS3 transform and transition.

HTML:

<ahref="#"id="r">Reset</a><divid="z"><!-- this is the button container --></div>

jQuery:

$('#z a').click(function(e){
    e.preventDefault();
    $('#z').addClass('dock');
});
$('#r').click(function(e){
    e.preventDefault();
    $('#z').removeClass('dock');
});

CSS:

#z {
    position: absolute; left: 150px; top: 150px;
    transform: scale(1.1);
    -o-transform: scale(1.1);
    -moz-transform: scale(1.1);
    -webkit-tranform: scale(1.1);
    transition: 0.6s ease-in;
    -o-transition: 0.6s ease-in;
    -moz-transition: 0.6s ease-in;
    -webkit-transition: 0.6s ease-in;
    -webkit-backface-visibility: hidden; // prevent webkit bug
}

#z.dock {
    left: -70px; top: -10px;
    transform: scale(0.5);
    -o-transform: scale(0.5);
    -moz-transform: scale(0.5);
    -webkit-transform: scale(0.5);
    transition: 1s ease-out;
    -o-transition: 1s ease-out;
    -moz-transition: 1s ease-out;
    -webkit-transition: 1s ease-out;
    -webkit-backface-visibility: hidden; // prevent webkit bug
}

See demo

Solution 2:

Looks like I found some time after all. Seems to work for me in Chrome 15, so will probably work in other webkit-based browsers as well. It's only a starting point so the cross-browser code needs some attention.

Edit:Updated demo which uses the shrinkTo jQuery plugin

HTML

<ahref="#"id="shrinkify">Shrinkify me</a><divid="small"></div><divid="big"><ahref="#"></a><ahref="#"></a><ahref="#"></a><ahref="#"></a><ahref="#"></a><ahref="#"></a><ahref="#"></a><ahref="#"></a><ahref="#"></a></div>

CSS

#big {
    width:240px;
    height:240px;
    border:4px solid black;
    padding:5px;
    text-align:center;
    display:table-cell; 
    vertical-align:middle;
    position:relative;
    left:200px;
}

#biga {
    display:inline-block;
    border:2px solid black;
    -webkit-border-radius:5px;
    width:55px;
    height:55px;
}

#small {
    position:absolute;
    top:100px;
    width:120px;
    height:120px;
    visibility:hidden;
}

JavaScript

$('#shrinkify').click(function() {
    $('div#big').shrinkTo($('#small'), {
        duration: 1000,
        easing: 'swing',
        opacity: false
    });
    returnfalse;
});

Post a Comment for "Jquery / Jquery Tools Getting Smaller Effect"