在Widget代码中使用javascript从左向右滑动光标图像

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

本文关键字:图像 光标 代码 Widget javascript      更新时间:2023-09-26

我想要这个小部件代码。我检查了所有的帖子,但它们对没有帮助

此代码在没有HTML&小工具中的CSS。但我想用下面的代码做一个类似鼠标悬停的演示。我糟糕的英语

<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;" />

您只需使用CSS3 transition就可以做到这一点。检查以下更新。

* {
  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" />