I am trying to make an effect, where the background - image will be revealed, as I hover over it.
The problem is that I want to make it for a specific area, not the full view port.
The background-image of an absolute item, with background fixed, it is taking the whole screen automatically. So I am trying to limit it inside a specific div.
All the effect to be happening for a specific div.
Having tried many things but cannot make it working.
The box should contain the image, but it will reveal only the part that I am hovering, is this more clear?
In the your first code this was happening, but the full image was not in the box, it was part of the image there. As it was stretching across all the browser width, but we just seeing the part inside the div.
Ok If I’m understanding that you want a whole image in the div then you can’t use the background-attachment fixed trick because fixed backgrounds are always in relation to the viewport. The circle showing the image relies on the same mechanism to show the relevant part of the image.
If you want a background image to fill the box then you need a normal background image but you would then need to calculate the offsets of the image in order to display the right part of the image in the circle. This could get very messy and need a lot of background-position manipulating.
I’m sure one of the JS gurus watching here could do that for you but a css solution may be easier depending on your use case. Rather than showing an image in the circle lets instead rub everything out that is outside the circle using box-shadow and then we don’t need to have anything at all in the circle as you will see the background underneath.
The solution with the box-shadow is awesome great thought.
One thing that I am trying, is that when the cursor moves outside of the div, the circle will follow - hide / fade-out in some way, because now it is stuck there.
It should be easy enough to make the circle go all the way out of the box so you can’t see it.
If you wanted it to fade out when it touched an edge (or passed through an edge ) would be a lot more complicated as you’d have to track the positions and then apply a fade class to the element.
I’ll have a look tomorrow unless someone else jumps in first
I’m on a mobile at the moment so can’t change the code but it’s because the circle has no width or height to start with. You could hardcode the JS value at the required width or perhaps better to leave the circle at its original size and transition the background of the circle from black to transparent.