我發現這個小提琴http://jsfiddle.net/22sxotje/如果我將鼠標懸停在類lochtonialcaress
上的元素,那麼圖像lochtonialcaress.png
出現。Mouseover上的顯示圖像(在jsfiddle內部的工作示例)
我怎樣才能改變這種腳本來顯示圖像(classname.png)與類名任何元素,但什麼都不顯示,如果沒有圖像classname.png
它的工作,如果我將它複製並只改變類名,但如何加入一起:
$(document).ready(function() {
var yOff = 15;
var xOff = -20;
var pathToImage = "http://x.jupe.pl/lochtonialcaress.png";
$(".lochtonialcaress").hover(function (e) {
$("body").append("<p id='image-when-hovering-text'><img src='" + pathToImage + "'/></p>");
$("#image-when-hovering-text")
.css("position", "absolute")
.css("top", (e.pageY - yOff) + "px")
.css("left", (e.pageX + xOff) + "px")
.fadeIn("fast");
},
function() {
$("#image-when-hovering-text").remove();
});
$(".lochtonialcaress").mousemove(function (e) {
$("#image-when-hovering-text")
.css("top", (e.pageY - yOff) + "px")
.css("left", (e.pageX + xOff) + "px");
});
});
$(document).ready(function() {
var yOff = 15;
var xOff = -20;
var pathToImage = "http://x.jupe.pl/vollsprotector.png";
$(".vollsprotector").hover(function (e) {
$("body").append("<p id='image-when-hovering-text'><img src='" + pathToImage + "'/></p>");
$("#image-when-hovering-text")
.css("position", "absolute")
.css("top", (e.pageY - yOff) + "px")
.css("left", (e.pageX + xOff) + "px")
.fadeIn("fast");
},
function() {
$("#image-when-hovering-text").remove();
});
$(".vollsprotector").mousemove(function (e) {
$("#image-when-hovering-text")
.css("top", (e.pageY - yOff) + "px")
.css("left", (e.pageX + xOff) + "px");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>This is my paragraph with a <a class="lochtonialcaress" href="#">very special hover</a> effect on the link.</p>
<p><span class="vollsprotector">Lorem</span> ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirm od tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
<p>The hovering works with every element that has <span class="no-image"> a class of <em>"text-hover-image"</em></span>
歡迎SO。你試過什麼了? – haxxxton 2014-12-11 02:14:28
@haxxxton我嘗試做沒有jQuery的,但後來我發現這個jsfiddle和它幾乎我需要的,但我一無所知jquery也我的JavaScript的知識不是令人印象深刻,我不知道如何位這個jquery的例子:( – XnIcRaM 2014-12-11 02:38:08