how to move/slide an image from left to right

前端 未结 3 1419
耶瑟儿~
耶瑟儿~ 2021-01-03 17:26

I want to slide or move a image from left to right something like in

http://rajeevkumarsingh.wix.com/pramtechnology

The read pentagonal box that moves Ok !<

3条回答
  •  醉梦人生
    2021-01-03 18:13

    var animate, left=0, imgObj=null;
    
    function init(){
    
       imgObj = document.getElementById('myImage');
       imgObj.style.position= 'absolute';
       imgObj.style.top = '240px';
       imgObj.style.left = '-300px';
       imgObj.style.visibility='hidden';
    
       moveRight();
    }
    
    function moveRight(){
        left = parseInt(imgObj.style.left, 10);
    
        if (10 >= left) {
            imgObj.style.left = (left + 5) + 'px';
            imgObj.style.visibility='visible';
    
            animate = setTimeout(function(){moveRight();},20); // call moveRight in 20msec
    
            //stopanimate = setTimeout(moveRight,20);
        } else {
            stop();
        }
        //f();
    }
    
    function stop(){
       clearTimeout(animate);
    }
    
    window.onload = function() {init();};
    

提交回复
热议问题