I am trying to show a large image on hovering a thumbnail in jquery and CSS. I have 2 images as
<td>
<% if camera["is_public"] == "t" %>
<img src="https://media.evercam.io/v1/cameras/<%= camera["exid"] %>/thumbnail?" height="32" class="thumbnails">
<img src="https://media.evercam.io/v1/cameras/<%= camera["exid"] %>/thumbnail?" height="600" class="full-image">
<% else %>
<img src="https://media.evercam.io/v1/cameras/<%= camera["exid"] %>/thumbnail?api_id=<%= camera["api_id"] %>&api_key=<%= camera["api_key"] %>" height="32" class="thumbnails">
<img src="https://media.evercam.io/v1/cameras/<%= camera["exid"] %>/thumbnail?api_id=<%= camera["api_id"] %>&api_key=<%= camera["api_key"] %>" height="600" class="full-image">
<% end %>
</td>
and CSS as
.full-image {
display: none;
z-index: 99999;
top: 10%;
width: 600px;
height: auto;
right: 34%;
}
on hovering .thumbnail am triggering this function
onImageHover = ->
$("#snapshots_datatables").on "mouseover", ".thumbnails", ->
nextImage = $(this).siblings(".full-image")
$(nextImage).css({"top": "10%"})
nextImage.show()
$("#snapshots_datatables").on "mouseout", ".thumbnails", ->
nextImage.hide()
all my problem is that i want to show height: 600 image on hovering .thumbnail BUT in center of screen regarding screen size and Scroll. Even i scroll down image should apprea in center of screen. any help will be appreciated. I had zero luck in adding CSS by myself.
EDIT: same as bootstrap model even its clicked at very down in screen but it appears in middle of screen.
You don't really need javascript for this. I think css would do the trick.
First you want to make sure the .full-image is always in the center of your screen.
.full-image {
position: fixed;
width: 600px;
height: 600px;
left: 50%;
top: 50%;
margin-left: -300px;
margin-top: -300px;
background: red;
display: none;
}
Then you want to make it appear when you hover on the .thumbnail
.thumbnail:hover .full-image {
display: block;
}
Here's the working demo
http://codepen.io/Jeffersonvdh/pen/GZBMBQ
Related
I need to one image overlap an another. But the second image have background color and I need the first image between the second and second's background-color. It is possible? Already tried to made a new "div class" instead of style="background-color". Now i am stuck with this:
.mainRunner {
position: relative;
}
.firstimage {
position: relative;
z-index: 2;
}
.secondimage {
position: relative;
z-index: 3;
top: -75px;
}
.background {
position: relative;
z-index: 1
}
<div class="firstimage" style="max-width: 1170px;"><img src="" alt="" title="" style="width: 100%;" max-width="1168" height="399" caption="false" /></div>
<div class="background" style="background-color: #f2e5df;">
<div class="secondimage">
<img src="" alt="" title="" />
</div></div>
You can't give certain properties of an element different z-index values. However for certain elements like a div you can use ::before and ::after pseudo elements. And you can set a z-index on those, effectively creating three layers. More information here.
In this case you can create a div with the middle img inside. Then add a ::before and ::after to that div. Giving one a background color and a z-index of -1. And the other a background image and a z-index of 1.
In the example below I also added some margin and a border around the inital div so you can better see what is going on.
.image {
margin: 20px 0 0 20px;
position: relative;
border: 3px solid coral;
width: 200px;
height: 300px;
}
.image::before,
.image::after {
content: '';
display: block;
width: 200px;
height: 300px;
position: absolute;
}
.image::before {
z-index: -1;
background: cornflowerblue;
top: 20px;
left: 20px;
}
.image::after {
z-index: 1;
background: url("https://www.fillmurray.com/200/300");
top: -20px;
left: -20px;
}
<div class="image"><img src="https://www.fillmurray.com/200/300" /></div>
If I understand right what you're trying to achieve, you probably should be placing the images within background div and placing the second image with position: absolute:
<style>
.mainRunner {
position: relative;
}
.firstimage {
position: relative;
z-index: 2;
}
.secondimage {
position: absolute;
z-index: 3;
top: 20px; /* use top and left values to place the image exactly where you want it over the first image */
left: 20px
}
.background {
position: relative;
z-index: 1;
background-color: #f2e5df;
}
</style>
<div class="mainRunner">
<div class="background">
<img src="image1.png" class="firstimage" />
<img src="image2.png" class="secondimage " />
</div>
</div>
It sets the background color as the back-most element, then on top of it the secondimage and the firstimage.
Thank everyone for their ideas. In the end the solution was simple. In the style was the double definition of second image. And the first of them was just partly commented. So my first post working right like this:
.secondimage img{
max-width: 100%;
height: auto;
position: relative;
top: -75px;
margin: 5px;
margin-bottom: 10px;
}
Now just need to find out how to close this question...
Thank you :)
The answer is simply no... there is no way to address a z-index to specifically a background of an element, z-index and all the other CSS properties work on the entire element, not on only its background.
You're going to have to find another way to do this, have you thought of using a div with not content, and the same size of the image, and then just setting a background color to that specific div?
I have this image appended to a div JSFiddle
and my Div is inside a modal. I'v tried to display by default the bottom left quarter (like filling the div) and to allow the user to scroll horizontally and vertically to see the rest of the image but it seems that I have some blue areas and I cannot scroll till the end of the image.
imgUrl = "nerdist.com/wp-content/uploads/2018/02/year-or-the-tank-girl-header.jpg"
$('.img-wrapper').append($('<img id="theImg">').attr({
'src': 'https://' + imgUrl ,
'alt': 'test image'
})
)
.img-wrapper {
overflow: hidden;
height: 400px;
background-color: blue;
position: relative;
overflow-x:auto;
overflow-y:auto;
}
.img-wrapper > img {
display: inline-block;
height: 150%;
width: 150%;
position: relative;
top: -50%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myDiv" class="img-wrapper">
</div>
Is there a way to display, when the modal is open, just the bottom left quarter of the image and allow the user to scroll XY to see the rest of it?
I'm new in HTML programming so please be gentle :)
https://jsfiddle.net/2mLbhmuL/61/
CSS:
.img-wrapper {
overflow: auto; /* adds scrollbars */
height: 400px;
background-color: blue;
position: relative;
}
.img-wrapper > img {
height: 200%; /* probably looks neater if auto */
width: 200%; /* double width image to show only first quarter */
vertical-align: bottom; /* moves image to true text bottom */
}
JQuery
Add the following ScrollTop(9999) to the end of your existing JQ to jump the div to the bottom.
.scrollTop(99999)
It's a bit nasty hard-coding a large number but it saves getting a handle to the element (which would allow you to use its real height).
Note:
The vertical-align: bottom is needed for the image to display without showing your blue area underneath. The reason for that is an image is naturally positioned on the baseline of text, so the blue area you were seeing is the space for hanging letters.
The solution is quite simple:
Don't use display: inline-block; as it will place the image will be placed inline and with some margin down. Instead use display: block
The top: -50%; is also moving the picture 50% up leaving it's original position blank
You make this simple:
.img-wrapper {
height: 400px;
width:400px;
background-color: blue;
position: relative;
overflow-x:auto;
overflow-y:auto;
}
.img-wrapper > img {
position: relative;
}
<div id="myDiv" class="img-wrapper">
<img src="https://nerdist.com/wp-content/uploads/2018/02/year-or-the-tank-girl-header.jpg" id="theImg"/>
</div>
Try this: (Assumption - You will adjust for your image size and containing div size as required)
html
<div id="myDiv" class="img-wrapper">
<img src="http://nerdist.com/wp-content/uploads/2018/02/year-or-the-tank-girl-header.jpg">
</div>
JS:
var d = $('#myDiv');
d.scrollTop(d.prop("scrollHeight"));
CSS:
.img-wrapper {
height: 400px;
background-color: blue;
position: relative;
overflow-x:auto;
overflow-y:auto;
}
.img-wrapper > img {
display: inline-block;
position: relative;
border:1px solid red
}
so i have 3 images they all are using the same code with different style of course first image is on left second image is in middle and third is on right.
bottom: 10;
left: 0;
right: 0;
position: fixed;
text-align: center;
margin: 0px auto;
okay so the issue i'm having is when you are to hover on the image it can only hover the pointer on either top part of the image but when hovering over the image on bottom then it detects no link at all.
sample of code for image I'm using
<a href="/"><img style="width: 130px; height: 130px; border: 0px; display: inline;" src="img">
</a>
All of the images are different sizes but one the first image i resized the image to like 150px width and 100 width height then the hover start working but i want the image to be hover on 100px width and 50px height and when i do that it only hovers over right side of the image and this image is the first image on left. Second image i tried resizing but it only hovers on top of the image. any help will be appreciated :)
There's a problem in your CSS. All of your <div>'s containing the anchor tags and the images have a fixed position along with left: 0 which is why they are overlapping. You can achieve what you're trying to do like this, I've modified the HTML and added new CSS:
#images {
text-align: center;
}
#images a:nth-child(2) {
display: inline-block;
float: left;
}
#images a:last-child {
display: inline-block;
float: right;
}
<div id="images"><img style="width: 100px; height: 100px; border: 0;" src="http://7brands.com/wp-content/uploads/2014/07/google-maps-logo.jpg" />
<img style="width: 100px; height: 80px; border: 0;" src="http://7brands.com/wp-content/uploads/2014/07/google-maps-logo.jpg" />
<img style="width: 100px; height: 80px; border: 0;" src="http://7brands.com/wp-content/uploads/2014/07/google-maps-logo.jpg" /></div>
I dont know exactly your need, from my understand you can do it as follow:
Add this css styles and hover the image:
#img1 {
bottom: 10;
left:0;
right:0;
position: fixed;
text-align:center;
margin: 0px auto
z-index:1;
}
#img1 img:hover {
width:100px !important;
height:50px !important;}
Fiddle:http://jsfiddle.net/1hwm3epj/16/
I'm trying to overlay a logo on top of a background image and I'm having a bit of trouble with it. Here is my html for the background image; the javascript makes the image refresh every second so it is like a video stream. The dublin-rememberance-floor2 is the image, there is some other javascript that gets this image from a database and puts it here full screen. The logo is logo.svg, I want this to go up in the left hand top corner but at the moment it is just going in behind the background and I have tried a couple of methods without success.
<body>
<img class="fullBG" evercam='dublin-rememberance-floor2' refresh="1000" alt="" /> <div class="logo">
<img height="25" src="http://www.evercam.io/img/logo.svg" border="0" width="175" alt="http://www.evercam.com/" />
</div>
width="175" alt="http://www.evercam.com/" />
<img />
<script>
$(document).ready(function () {
Evercam.setApiUrl('http://api.evercam.io/v1');
});
</script>
</body>
Here is my css for the fullBG and logo;
.fullBG {
position: absolute;
top: 0px;
left: 0px;
overflow: auto;
z-index: 1;
width:100%;
height:100%;
}
.logo{
position: absolute;
top: 0;
right: 0;
}
I changed my css and this seemed to work
.fullBG {
position: absolute;
top: 0px;
left: 0px;
overflow: auto;
width:100%;
height:100%;
}
.logo{
position: absolute;
top: 0;
right: 0;
z-index: 1;
}
One thing you can do is that you can give z-index of logo > z-index of background so it will come on top of background..
I think you should position your a href link of logo also absolute.
another thing there is no separate closing img as you have done and trying to put "a href" in between of images.
Here is an image slideshow.
My homepage will have such a slideshow. But the top row (sites, files, editor etc) will move to the bottom.
The slide show (with one large image at a time and a row of small images below) will stretch over the full page.
How can I make it stretch over the full page as i explained before?
Edit: Actually, what I want to know is how can I make an image (not a background image) stretch over the full page with a little space below?
CSS:
<style>
.big, .list {
position: fixed;
bottom: 100px;
left: 0;
width: 100%;
height: 100%;
}
.list {
bottom: 0;
height: 100px;
background: #000;
}
</style>
HTML:
<img src="http://goo.gl/8JnW8" class="big" alt="" />
<div class="list">{images}</div>
Let's say this is the HTML:
<body>
<img id="bgimg" src="image.jpg" alt="Image"/>
</body>
You can style it like this:
body {
position: relative;
width: 100%;
height: 100%;
}
#bgimg {
top: 0;
left: 0;
display: block;
position: absolute;
width: 100%;
height: 98%;
}
This should work.