javascript - 使用 Widget 代码中的 javascript 将光标图像左滑向右移动

标签 javascript html css hover widget

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

此代码在 Widget 中无需 HTML 和 CSS 即可运行。 但我想做像这样的鼠标悬停DEMO用下面的代码。我的英语不好

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

关于javascript - 使用 Widget 代码中的 javascript 将光标图像左滑向右移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37292933/

相关文章:

javascript - codeigniter 无法在单独的 js 文件中回显 site_url

php - 使用 codeigniter 时如何在字段集中居中输入标签?

PHP json_encode 将本地语言字符作为 html 实体返回。需要 unicode 格式的输出

javascript - Jquery Splitter bar 100%面板高度

html - 如何垂直对齐div中的元素?

javascript - 我如何使 div 更改位置以适合屏幕

javascript - Material UI 中的对话框以奇怪的灰色背景打开

javascript - 如何在云函数中访问 firebase 数据库中的另一个数据?

javascript - 在左侧边栏中,我只想将打开的最近点击的模块作为事件模块的一部分

javascript - 将 CSS 应用于当前页面链接不起作用