positioning images inside div element - html

I have created a slideshow which sits inside a div element. The images are not added in the html, but through javascript and adjust their class attribute to fade In and Out.
I am trying to add buttons over the images for next and previous slide.
Problem I'm having is that the img tags are showing on screen and inside the html structure shown in the debugger, but when I examine the element the div is at the top with height 0px above the images? So the images are not sitting inside.
The reason for this is that I want to add buttons positioned relative to the containing div element (to ensure they stay on the left/ middle and right/middle of the image when the window is resized.
To clarify; I need to add the images inside the div #container so that the size/ position are relative to it. I then want to add the other images as buttons also relative to the div so that they remain in position when the screen is resized. How do I do this?
Demo
HTML
<div id="container">
<!--IMG elements created in JS go here-->
<img class="previous_button" src="symbols/PreviousArrow.png"/>
<img class="next_button" src="symbols/NextArrow.png"/>
</div>
<script src = "jsScript.js" type="text/javascript"></script>
CSS
#container {
position: relative;
z-index:1;
width:50%;
height:600px;
top:20%;
border:10px solid black;
}
#container img#main {
transition:opacity 2s;
z-index:1;
position:absolute;
top:20%;
opacity:0;
width:25%;
}
#container img#main.fadeIn {
opacity:1;
z-index:100;
}
.previous_button {
position:absolute;
margin-left:8%;
height:35px;
width:35px;
}
.previous_button:hover {
opacity:1;
}
.next_button {
position: absolute;
height:35px;
width:35px;
}
.next_button:hover {
opacity:1;
}
JAVASCRIPT
var curIndex=0;
var imgDuration=2000;
var timeout;
var images;
var links;
var container=document.getElementById("container");
function getImageAndLink(){
images=document.querySelectorAll('img[id]');
};
var imageArray=[
{link:"page1.html", src:"image1.gif", id:"main"},
{link:"page2.html", src:"image2.gif", id:"main"},
{link:"page3.html", src:"image3.gif", id:"main"}
];
function create(arr){
for (i = 0; i < arr.length; i++) {
var imgEl = document.createElement("img");
imgEl.src=arr[i].src;
var id=arr[i].id;
imgEl.setAttribute("id",id);
var imgElA = document.createElement("a");
var link=arr[i].link;
imgElA.setAttribute("href", link);
imgElA.setAttribute("id",id);
imgElA.appendChild(imgEl);
container.appendChild(imgElA);
}
};
function slideshow() {
images.item(curIndex).className="fadeIn";
links.item(curIndex).className="fadeIn";
var interval=setInterval(function(){
images.item(curIndex).className="";
curIndex++;
if (curIndex==images.length) {
curIndex=0;
};
images.item(curIndex).className="fadeIn";
},imgDuration);
function stopSlide(){
clearInterval(interval)
};
container.addEventListener('mouseover', stopSlide, false);
container.addEventListener('mouseout', slideshow, false);
};
create(imageArray);
getImageAndLink();
slideshow();

Looks like your issue is that the inner content of the DIV has Absolute position and then they come out of the DIV on the dom, so makes it to have the 0 height.
with taking out the absolut position of those seem to have the height (added a border to the div so that you can see):
took out the position of these like this:
.previous_button {
margin-left:8%;
height:35px;
width:35px;
}
https://jsfiddle.net/gqjcpa0m/3/

Related

Flipping animation behaving very differently in other browsers

I am currently working on making a flipping animation on some divs.
However, I have found that it works incorrectly and differently in every browser that I have tried. Only Edge works the way that I want.
I want clicking the "flip" text to flip over in order to show the .flipping-view-back div, and hide the .flipping-view-front div. Additionally, the toolbar with position:fixed on the back div should be fixed at the top of the page even when scrolling.
In reality, this is only working in some browsers.
On Edge: This is working exactly how I want it to. Video
On Chrome: The front div flips over, but there is no back div visible behind it. The back div only pops in once the rotation transition has fully completed. Strangely, scrolling at any time during the flip will also trigger the back div to pop in. Also, scrolling down moves the fixed div out of sight. Video
On iOS Safari: This flips correctly, but scrolling down moves the fixed div out of sight. Video
In all these videos, I clicked on the flip text and waited for the animation to finish. Then I scrolled down.
How can I make the flip animation correct and keep the fixed div at the top in all browsers?
var currView = 0;
const rotatingViewElem = document.querySelector(".main");
const VIEW_FEED = 0;
const VIEW_FLIPPING_SEND = 1;
var viewFeedElem = document.querySelector(".view-positioner.feed");
var viewCreateElem = document.querySelector(".view-positioner.create");
var viewSelectRecipientsElem = document.querySelector(".view-positioner.select-recipients");
var viewFlippingSendElem = document.querySelector(".view-positioner.flipping-send");
var viewsList = [viewFlippingSendElem];
function flipView(isGoForward) {
var flippingElem = viewsList[currView];
var globalRotate;
if (isGoForward) {
globalRotate = "rotateY(180deg)";//flip around
} else {
globalRotate = "rotateY(0deg)";
}
flippingElem.style.transform = globalRotate;
}
document.querySelector(".create-send-button").addEventListener("click", function (e) { flipView(true) })
body, html{
width:100%;
height:100%;
margin:0px;
overflow:hidden;
}
.main{
perspective: 2000px;
height:100%;
}
.flipping-view-wrapper{
transform: rotateY(0);
transform-style: preserve-3d;
transition: transform 5.5s;
}
body{
height: 100%;
}
.view{
transform-style: preserve-3d;
position: relative;
padding-top:1px;
overflow-y:auto;
height: calc(100% - 1px);
width:100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.view-positioner{
position: absolute;
left:0px;
top:0px;
width:100%;
height:100%;
}
.flipping-view-front{
background-color: pink;
transform: rotateY(0deg);
}
.flipping-view-back{
background-color: green;
transform:rotateY(180deg);
}
.create-send-button{
cursor: pointer;
}
/* begin top toolbar */
.top-toolbar{
position:fixed;
top:0px;
left:0px;
width:100%;
height:55px;
background:#FFFB00;
}
<!DOCTYPE html>
<html>
<body class="lightblue">
<div class="main">
<div class="view-positioner flipping-send flipping-view-wrapper lightblue ">
<div class="view-positioner view create flipping-view-front">
<div class="create-inputs center">
<div class="create-send-button" style="font-size: 50px;">
flip to the backside this is long so you can see
</div>
</div>
</div>
<div class="view-positioner view select-recipients lightblue flipping-view-back">
<div class="top-toolbar">
fixed
</div>
<div style="width:10px">Long text a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a</div>
</div>
</div>
</div>
</body>
</html>
Could have something to do with the browsers itself, maybe look into -webkit. There are webkits for different browser so you might need to use multiple webkits for different browsers
What is WebKit and how is it related to CSS?
That post might give you some more info

Disable mouse wheel inside of ul{position:fixed}

I am using wordpress site. I created menu bar, inside of sub-menu, used position:fixed element. Anybody tell me how can i disable mousewheel inside of that sub-menu. That means i don't want page scroll inside of that sub-menu.
Please anyone help me.
You can use CSS property overflow: hidden; which specifies what happens if content overflows an element's box.
Using overflow: hidden; allow you to do not show up the scroll bar and so do not allowing scrolling at all including mouse weal.
Here below a very generic example, please consider to add your real markup in your question for a fix on your real app code.
https://jsfiddle.net/bxohL8tt/2/
#sub-menu{
width:250px;
height: 100px;
background-color:red;
overflow: hidden;
}
If the element that is scrolling on mouse-wheel event is the body, or even some other element, you can use JavaScript to prevent it from scrolling while your menu has "focus" like this:
var menuBar = document.getElementById('menuBar');
menuBar.onmouseover = function()
{
document.body.style.overflow = 'hidden';
};
menuBar.onmouseout = function()
{
document.body.style.overflow = 'auto';
};
Add the above inside a <script> element at the end of your main HTML source-code and it should work.
You can do this by the following code:
$("sub-menu-selector").bind("wheel mousewheel", function() {
return false;
});
For example: (The example shows the disabling on the menu but it's just the same)
$(".menu").bind("wheel mousewheel", function() {
return false;
});
body {
margin:0;
}
.menu {
background:black;
color:#fff;
position:fixed;
width:100%;
padding:15px;
}
.content {
height:1500px;
background:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="menu">
Menu
</div>
<div class="content"></div>

How to limit the view of a larger HTML <canvas> "inside" its parent <div>?

I've got a 5500 pxl wide panorama img (with usemap='#imagemap') on which I've overlain a canvas. These are parented inside a div.
Everything works as expected; the img view is restricted to the div, and can be scrolled. But the complete (wiiiide) canvas is visible in the browser window.
In addition, the canvas doesn't scroll with the div/img. I have to move it in an onscroll().
Edit: Here's a fiddle http://jsfiddle.net/91y2upam/1/ showing the canvas (outlined in green) escaping from the div.
Can a canvas be kept "inside" its parent div, with restricted view, and scrolled?
If so, how so?
The CSS:
#divPano {
width: 100%;
overflow: auto;
}
#cvsPano {
pointer-events: none; /* make the canvas transparent to the mouse - needed since canvas is position infront of image */
position: absolute;
}
and HTML:
<div name="divPano" id="divPano">
<canvas id='cvsPano'></canvas>
<img name='imgPano' id='imgPano' usemap='#mapPano' src='Pano/Pano0H500s.jpg' >
</div>
and the overlay JS (called from onload()):
function cvsInit(cvs, img) {
var x, y, w, h;
// get it's position and width+height
x = img.offsetLeft;
y = img.offsetTop;
w = img.width;
h = img.height;
// place cvsPano in front of the image
cvs.style.zIndex = 1;
cvs.parentNode.style.zIndex = 2; // <- this didn't work :-(
// position it over the image
cvs.style.left = x+'px';
cvs.style.top = y+'px';
// make same size as the image
cvs.setAttribute('width', w+'px');
cvs.setAttribute('height', h+'px');
// get it's context
hdc = cvs.getContext('2d');
// set the 'default' values for the colour/width of fill/stroke operations
hdc.strokeStyle = '#007700';
hdc.lineWidth = 1;
} // function cvsInit()
Make the parent position:relative and the oversized child canvas position:absolute.
Add scrollbars with overflow:scroll or
Pan programmatically with the parent overflow:hidden and moving the canvas with left:-100px.
Pan using scrollbars
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
var img=new Image();
img.onload=function(){
ctx.drawImage(img,0,0,img.width,img.height,0,0,canvas.width,canvas.height);
}
img.src="https://dl.dropboxusercontent.com/u/139992952/stackoverflow/canvas%20compositing.png";
body{ background-color: ivory; padding:50px; }
canvas{position:absolute; border:1px solid red;}
#parent{position:relative; overflow:scroll; width:300px; height:300px; border:2px solid blue; }
<div id=parent>
<canvas id="canvas" width=800 height=500></canvas>
</div>
Pan programatically
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
$myslider=$('#myslider');
$myslider.attr({min:-200,max:0}).val(0);
$myslider.on('input change',function(){
$('#canvas').css('left',parseInt($(this).val()));
});
var img=new Image();
img.onload=function(){
ctx.drawImage(img,0,0,img.width,img.height,0,0,canvas.width,canvas.height);
}
img.src="https://dl.dropboxusercontent.com/u/139992952/stackoverflow/canvas%20compositing.png";
body{ background-color: ivory; padding:50px; }
canvas{position:absolute; left:0px; border:1px solid red;}
#parent{position:relative; overflow:hidden; width:300px; height:300px; border:2px solid blue; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input id=myslider type=range>
<br>
<div id=parent>
<canvas id="canvas" width=800 height=500></canvas>
</div>
In the css, try changing the property overflow to something else like:
overflow: scroll;
Maybe that way it will scroll with the page.

Position fixed stop in particular section

Please see my fiddle. In this fiddle, the black box is fixed on page. If we scroll the page the black box is overlap the map also. I want to stop the fixed position before the map. If we scorll the page after the map, black box should stay before the map. How can I do?
CSS:
.item{ background:#eee; padding:10px; width:50%; margin-bottom:15px;}
.new_icon{ position:fixed; width:100px; height:100px; background:#000; right:10px;}
http://jsfiddle.net/6f8HK/
No need for javascript, add an id to your iframe, set the css to:
#map
{
position:relative;
z-index:2;
}
And give your fixed element a lower z-index:
.new_icon {
position:fixed;
width:100px;
height:100px;
background:#000;
right:10px;
z-index:1;
}
Js fiddle
Add z-index: -1; to .new_icon
DEMO
Try this Working Fiddle.
JQUERY:
$(window).scroll(function() {
if ($(this).scrollTop() > 450)
{
$('.new_icon').fadeOut();
}
else
{
$('.new_icon').fadeIn();
}
});
NOTE : use can use .show/.hide if you don't like the fadein/fadeout effect.

css expand text left and preserve container width

Please see this fiddle - http://jsfiddle.net/grimmus/vawE9/4/
<div class="refresh">
<div class="date" id="date">
As of 1/10/2013 16:44 2013 (GMT + 1)
</div>
<div class="loading"id="loading">
Loading...
</div>
</div>
In the blue box i am trying to toggle between the date and loading text. The date text can be varying width and i would like this width to stay the same when the text is hidden and the loading text is shown. The width of the date should expand to the left as far as necessary. The loading text should always be aligned left
I am having difficulty preserving the width of the box when showing the loading text. One solution i thought about was applying visibility hidden to the date text and then relatively positioning the loading text over this div with a higher z-index. It seems quite complicated and hope there is an easier solution.
Suggestions/Advice/Tips most welcome.
p.s needs to work in ie7+
Try this jsFiddle example:
jQuery
setInterval(function () {
$('#date').animate({
opacity: .01
}, 0, function () {
$('#loading').fadeIn(0).delay(2000).fadeOut(0, function () {
$('#date').animate({
opacity: 1
}, 0)
});
})
}, 4000);
CSS
body {
margin:25px;
}
.container {
background:#ccc;
height:50px;
width:100%;
}
.refresh {
background:blue;
color:#ccc;
height:20px;
float:right;
margin-right:25px;
min-width:150px;
text-align:left;
position:relative;
}
.date {
position:relative;
}
.loading {
display:none;
position:absolute;
top:0px;
}