You can use classc for this css transition. Code Example -
HTML
<div class="main">
Hello
</div>
CSS
.main {
background: green;
width: 100px;
height:100px;
margin-top:0px;
transition: margin-top 1s;
}
.set_margin {
margin-top:100px;
}
JQuery
$('.main').on('click', function() {
$(this).toggleClass('set_margin');
})
You can implement it as -
$('#image1').click(function() {
$('#div1').toggleClass('set_margin');
});
Fiddle
source
share