javascript - How to assign speed parameter to callback functions -
i've been trying figure out how assign speed callback function, couldn't.
in program.
html:
<button type="button" id="trigger">try</button> <div id="box"></div> <div id="bottom"></div>
css:
body { position: absolute; background-color: white; height: 1000%; } #box { position: absolute; height: 300px; width: 400px; top: 100px; left: 0px; margin: 0px; padding: 0px; border-color: black; background-color: black; opacity: 0; } #bottom { position: absolute; bottom: 0px; height: 100px; width: 100%; background-color: black; }
js:
$(document).ready(function () { $("#trigger").click(function () { var ele = document.getelementbyid('bottom'); var pos = ele.getboundingclientrect(); var x = pos.left; var y = pos.top; $("#box").animate({ left: "100px", opacity: "1" }, "slow", function () { window.scrollto(x, y); }, "slow"); }); });
on removing speed callback, works no success. how assign speed it, in advance.
fiddle: http://jsfiddle.net/9c8kr/
you've added speed 2 times, last 1 not valid.
if want animate scrolling, so
$(document).ready(function () { $("#trigger").click(function () { var ele = document.getelementbyid('bottom'); var pos = ele.getboundingclientrect(); var x = pos.left; var y = pos.top; $("#box").animate({ left: "100px", opacity: "1" }, "slow", function () { $('html, body').animate({ scrollleft : x, scrolltop : y }, 'slow'); }); }); });
Comments
Post a Comment