[英]I would like to move images in a div so the containing div displays them exactly their size
function mov_left() {
if (parseInt(document.getElementById('fold').style.left, 10) == 430) {
clearInterval(animel);
}
document.getElementById('fold').style.left = (parseInt(document.getElementById('fold').style.left, 10) - 10) + 'px';
}
animel = setInterval('mov_left()', 100);
This is the code I'm trying to use to move a <div>
containing 2 images so they can display the two images one at a time. 这是我试图用来移动包含2张图像的
<div>
的代码,以便它们可以一次显示两个图像。 However, the image just keeps moving to the left ignoring the if
statement in the function. 但是,图像只是一直向左移动而忽略了函数中的
if
语句。
Help please. 请帮助。
well I've fiddled with it, not really much change but I know this works: 好吧,我一直在摆弄它,虽然变化不大,但是我知道这可行:
function mov_left() {
var el = document.getElementById('fold');
if (parseInt(el.style.left, 10) == 430) {
clearInterval(animel);
}
el.style.left = (parseInt(el.style.left, 10) - 10) + 'px';
}
animel = setInterval(function () {mov_left(); }, 100);
JSfiddle: http://jsfiddle.net/m7q3H/42/ JSfiddle: http : //jsfiddle.net/m7q3H/42/
如果未设置element的左css属性,则element.style.left将返回一个空字符串,而parseInt将返回NAN。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.