Note that there are some explanatory texts on larger screens.

plurals
  1. POTarget class name but call function on unique ID
    primarykey
    data
    text
    <p><s>Ok I'm going to run this on the slowest ASP box I've ever seen before, so I'm not looking to use jQuery, I know it would make everything a lot easier but I need to keep my code as small as humanly possible.</s> I'm targeting users with the slowest internet I've ever seen and loading the entire jQuery file will be to much for their internet to take. So I'm not looking to use jQuery for this script.</p> <p>I'm trying to make a script that when the user hovers over the thumbnail the larger image pops up. I'm using the following javascript to achieve this:</p> <pre><code>var hoverImage = document.getElementById("largeImage"); function hoverZoom(selector) { this.node = document.querySelector(selector); if(this.node === null) { console.log("Node not found"); } return this.node.id; } hoverZoom.prototype.show = function(x, y) { var largeImageSrc = this.node.name; hoverImage.style.display = "block"; var largeWidth = hoverImage.offsetWidth; var largeHeight = hoverImage.offsetHeight; hoverImage.style.top = y - (largeHeight / 2) + "px"; hoverImage.style.left = x - (largeWidth / 2) + "px"; hoverImage.style.position = "absolute"; hoverImage.style.background = "url(" + largeImageSrc + ")"; } hoverZoom.prototype.hide = function() { hoverImage.style.display = "none"; } hoverZoom.prototype.checkCoords = function(x, y) { var id = document.getElementById(this.node.id); var elemTop = id.offsetTop; var elemLeft = id.offsetLeft; var elemHeight = id.offsetHeight; var elemWidth = id.offsetWidth; console.log(x + " " + y + " " + this.node.id + " " + id + " " + elemHeight + " " + elemWidth + " " + elemTop + " " + elemLeft); if(x &gt;= elemLeft &amp;&amp; x &lt;= elemLeft + elemWidth &amp;&amp; y &gt;= elemTop &amp;&amp; y &lt;= elemTop + elemHeight) { return true; } } document.body.onmousemove = function(e) { e = e || window.event; while(hoverZoomPI.checkCoords(e.clientX, e.clientY) === true) { var target = e.target || e.srcElement, offsetX = e.clientX, offsetY = e.clientY; return hoverZoomPI.show(offsetX, offsetY); } hoverZoomPI.hide(); } var hoverZoomPI = new hoverZoom(".test"); </code></pre> <p>My problem is that when I hover over another image with the same class name nothing happens. But when I hover over the first image with the class name it works.</p> <p>I've set up a jsFiddle with all my code and an example: <a href="http://jsfiddle.net/f7xqF/" rel="nofollow">http://jsfiddle.net/f7xqF/</a></p> <p>Thanks everybody for their help. I can't say enough about how much you guys have helped me over the last few years. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload