我目前正在做一个项目,我想知道是否有人可以帮助这段JS代码。我正在尝试让DIV在页面加载时移动。例如,假设时间是上午9点;我希望它移动100px,上午9:30am移动120px。
非常感谢。
function slide(element, pixels, duration) {
var start = new Date();
var start_x = parseInt(element.style.left, 10);
function frame() {
var now = new Date(),
elap = now - start,
frac = Math.min(elap / duration, 1),
pos = start_x + (pixels * frac);
element.style.left = (pos || 0) + "px";
if (frac < 1) {
window.requestAnimationFrame(frame);
}
}
window.requestAnimationFrame(frame);
}
var div = $('#slideme');
$('#slideme').load('#slideme', function() {
var elem = document.getElementById("slideme");
slide(elem, -200, 1000);
});发布于 2013-09-05 19:28:32
您可以使用jquery的animate函数。
$(document).ready(function() {
$( "#block" ).animate({
marginLeft: "+1200px",
}, 3000 );
});https://stackoverflow.com/questions/18634622
复制相似问题