简体   繁体   English

我想在div中移动图像,以便包含div的图像准确显示其大小

[英]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.

相关问题 如何实现类似于重力的div,以便当我将div拖近以粘合它们时,距离= 0? - How to achieve something like gravity to div so when I drag div close to glue them, distance =0? 我在div内有5张图像,如何移动单击的图像的位置,使其移动成为div内的第一张图像? - I have 5 images inside a div, and how can i move the position of a clicked image so that it moves to become the very first image inside the div? 响应式DIv包含2张图片 - Responsive DIv Containing 2 images 我想在DIV中合并所有图像并允许用户下载(js powered) - I would like to merge all images within DIV and allow user to download (js powered) 我如何将一个div移到另一个div之下,而顶部div仍然具有“ position:fixed”? - How would I move a div below another div and still have the top div have“position:fixed”? 我只想将html5视频替换为div,仅适用于移动/平板电脑用户,而无需让他们开始下载视频 - I would like to replace an html5 video with a div only for mobile/tablet users, WITHOUT having them start the download of the video 切换开/关在含有格和图像 - toggling on/off on containing div and images 创建一个包含滑动图像的div - create a div containing sliding images 包含图像的div的scrollHeight值 - scrollHeight value for a div containing images 我怎么做才能让div隐藏在一定的时间内 - How would i make it so that a div hides in a certain amount of time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM