jquery: how to change the size of a div from center -
jquery: how to change the size of a div from center -
when utilize jquery animate() function alter size of div, begins left-top point. how can create zoom center instead corner. example, code:
<div id="div1"></div> <style> #div1{ position: absolute; width: 50px; height: 50px; background-color: red; opacity: 0.4; top: 40%; left: 40%; border-radius: 1000px; margin: auto; } </style> <script src="jquery.js"></script> <script src="jquery.easing.1.3.js"></script> <script> $(document).ready(function(){ $("#div1").mouseover(function(){ $(this).animate( {width: 100, height: 100, opacity: 1}, {duration: 500, easing: "easeoutbounce"} ); }); $("#div1").mouseout(function(){ $(this).animate( {width: 50, height: 50, opacity: 0.4}, {duration: 500, easing: "easeoutbounce"} ); }); }); </script>
this alter left-top point want staring center. thanks!
here example using @schroedingers cat's suggestion. changed top , left positions pixel values rather percentages.
javascript:
$("#div1").mouseover(function() { $(this).animate({ width: 100, height: 100, top: 75, left: 75, opacity: 1 }, { duration: 500, easing: "easeoutbounce" }); }); $("#div1").mouseout(function() { $(this).animate({ width: 50, height: 50, top: 100, left: 100, opacity: 0.4 }, { duration: 500, easing: "easeoutbounce" }); });
css:
#div1{ position: absolute; width: 50px; height: 50px; background-color: red; opacity: 0.4; top: 100px; left: 100px; border-radius: 1000px; margin: auto; }
jquery
Comments
Post a Comment