我在Jquery/Javascript中寻找可以在悬停在图像上时更改H1内容的脚本.
想象一下,连续有6个不同的图像.当悬停在图像上时,会发生h1的变化.
这是我能得到的最接近的,但我想让它在Hover上工作,而不是点击.
var random = Math.floor(Math.random() * 1000);
var $li = $("#gallery li");
$li.eq(random % $li.length).addClass("on");
$("h1").text($("img", ".on").attr("alt"));
$("#gallery li").click(function() {
$("#gallery li").removeClass("on");
$(this).addClass("on");
$("h1").text($("img", ".on").attr("alt"));
});
Run Code Online (Sandbox Code Playgroud)
尝试使用hover回调.
$("#gallery li").on('hover', function(e) {
$("h1").text('Hovered');
}, function () {
$("h1").text('back to whatever');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
497 次 |
| 最近记录: |