<分区>
标签 javascript jquery html css
<分区>
我在实现 jquery 功能时遇到问题,该功能允许我将鼠标悬停在图像上并更改图像,然后在不悬停时将其恢复为原始图像。这是我目前所拥有的,任何帮助将不胜感激。
<div id="slideshow">
<img src="myPic.jpg" width="400" height="300" alt="pic" id="myImage"/>
</div>
$(document).ready(function(){
$("#myImage").hover(function(){
$("#myImage").attr("src", "http://timesofoman.com/uploads/images/2017/05/21/671029.JPG");
},function() {
$("#myImage").attr("src", "myPic.jpg");
});
});
}
最佳答案
如果你想在鼠标离开时改变图像,你必须添加 mouseout
事件。
$("#myImage").hover(function(){
$(this).attr("src",
"http://timesofoman.com/uploads/images/2017/05/21/671029.JPG");
}).on("mouseout",function(){
$(this).attr("src", "myPic.jpg");
});
$("#myImage").hover(function(){
$(this).attr("src",
"http://www.thehindu.com/news/national/other-states/article20605531.ece/alternates/LANDSCAPE_460/20TH-THGRP-RUPANI");
}).on("mouseout",function(){
$(this).attr("src", "http://www.thehindu.com/news/national/article20601353.ece/alternates/FREE_460/21THCRPF-02");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<img id="myImage" src="http://www.thehindu.com/news/national/other-states/article20605531.ece/alternates/LANDSCAPE_460/20TH-THGRP-RUPANI" />
关于javascript - .hover() Jquery 需要帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47405368/
相关文章:
javascript - 如何将 "pointers"存储到 React/Javascript 中一棵不可变树中的嵌套节点?
javascript - 在 Windows Phone 上禁用向右滑动到上一页
javascript - 如何使用嵌入式 javascript 在第 3 方网站上创建弹出窗口?
html - Bootstrap 4 六个盒子在同一行(响应式)?
javascript - phalcon volt "javascript_include"如何在包含 URL 中添加异步或延迟