简体   繁体   中英

Moving with cursor image left slide to right with javascript in Widget code

I want this widget code. I checked all posts, but they do not help

this code worked without HTML & CSS in Widget. But i want to do like mouse hover like this DEMO with below code. my bad english

<script type="text/javascript">
<!--
var imgObj = null;
var animate ;
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(){
    if (parseInt(imgObj.style.left)<=10)
    {
        imgObj.style.left = parseInt(imgObj.style.left) + 5 + 'px';
        imgObj.style.visibility='visible';
        animate = setTimeout(moveRight,20); // call moveRight in 20msec
       //stopanimate = setTimeout(moveRight,20);
    }
    else
       stop();
       f();
}

function stop(){
   clearTimeout(animate);
}
window.onload =init;
//-->
</script>
<img id="myImage" src="https://lh4.googleusercontent.com/proxy/LxuD_Ceq6NrRGBW2mF_6Cy9zeO_vqkV8ZTRMdzjc_LxE0InnXBLp1_BkWuyhlg0EMJPt-Njzzp5_4cuR562m6dh8QNTW_1kzsf9pXcXiKI2ZK6wEMJH2TAAiQqpQUewNMKI=s0-d" style="margin-left:170px;" />

You can do that with just CSS3 transition . Check below update.

 * { margin: 0px; padding: 0px; } img { cursor: pointer; position: relative; margin: -65px; /* Adjust this value to expose the image */ left: 0; transition: left .5s; } img:hover { left: 65px; /* Use same value as used as negative margin */ } 
 <img id="myImage" src="https://lh4.googleusercontent.com/proxy/LxuD_Ceq6NrRGBW2mF_6Cy9zeO_vqkV8ZTRMdzjc_LxE0InnXBLp1_BkWuyhlg0EMJPt-Njzzp5_4cuR562m6dh8QNTW_1kzsf9pXcXiKI2ZK6wEMJH2TAAiQqpQUewNMKI=s0-d" /> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM