Compare and contrast this JSfiddle in Chome (correct) and IE11 (very definitely not correct):
http://jsfiddle.net/Lr90ko3q/
IE seems to see the height of the CONTENT in the inner div, rather than the actual height of the div. In other words, if you add a couple more lines of content, the left/right arrows move down a bit.
Is this a known bug, and is there a usable workaround for it?
Thanks
(copy of JSfiddle code):
html {
box-sizing:border-box
}
*, *::before, *::after {
box-sizing:inherit
}
html, body {
position:relative;
width:100%;
height:100%
}
section {
width:60%;
height:60%;
position:relative;
background:rgba(0, 0, 0, 0.1)
}
section>.content {
display:table;
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
padding:50px
}
section>.content>div {
display:table-cell;
vertical-align:middle;
position:relative;
background:rgba(255, 0, 0, 0.2);
text-align:center
}
#left {
position:absolute;
left:5%;
top:50%;
margin:0;
transform:translateY(-50%)
}
#right {
position:absolute;
right:5%;
top:50%;
margin:0;
transform:translateY(-50%)
}
I fixed the issue by just adding JS that forces a fixed height on the table cell elements.
Also used native JS since the functionality is fairly simple and supported on each of the browsers.
Obviously replace .table/.table-cell with whatever you called your table/table-cell items that you're targeting.
"use strict";
var ua = navigator.userAgent.toLowerCase();
var ie_version = (ua.indexOf('msie') != -1) ? parseInt(ua.split('msie')[1]) : false;
if (!ie_version && ua.indexOf("trident") !== -1 && ua.indexOf("rv:11") !== -1)
{
ie_version = 11;
}
if (ie_version == 9 || ie_version == 10 || ie_version == 11)
{
(function(){
window.onresize = calculateTableCellHeights;
calculateTableCellHeights();
function calculateTableCellHeights() {
// Fixes IE9/10/11 bug where table-cell doesn't inherit table height
var tables = document.querySelectorAll(".table");
for (var t = 0; t < tables.length; ++t)
{
var table = tables[t];
var table_cells = table.querySelectorAll(".table-cell");
for (var c = 0; c < table_cells.length; ++c)
{
var table_cell = table_cells[c];
var display = window.getComputedStyle(table_cell, null).getPropertyValue("display");
if (display == "table-cell")
{
// Set fixed height
table_cell.style.height = table.offsetHeight+"px";
}
else
{
// If item is no longer a table-cell due to responsive stacking
// remove the height.
table_cell.style.height = "";
}
}
}
}
})();
}
Related
I have a fixed div(logo-fixed) that appears when scrolling 1070px from Top, but I don't want that, I like the div to appear when I scroll 50 pixels after another div(headerclass)
How can this be achieved?
9.
this is the code
(function($) {
$(".logo-fixed").css({"visibility": "hidden"});
$(document).scroll(function () {
var y = $(this).scrollTop();
if (y > 1070) {
$(".logo-fixed").css({"visibility": "visible"});
$('.logo-fixed').fadeIn(200);
} else {
$('.logo-fixed').hide(0);
}
});
})( jQuery );
.headerclass {
position:sticky;
top:0;
z-index:600;
}
.logo-fixed {
position:fixed;
top:0;
left:0;
width:224px;
height:120px;
z-index:1000;
background: url("#");
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
}
<div class="headerclass"></div>
<div class="logo-fixed"></div>
You can get the position of the headerclass element with $(.headerclass').scrollTop() and then compare that to y in your conditional, instead of 1070.
Example:
if (y > 1070) {
gets replaced with
if (y > $(.headerclass').scrollTop() + 50 )
I've created a table that is contained within a section of my webpage and can scroll over the x and y axis to view everything. My problem so far is that the table can scroll along the y-axis when overflowing, but not the x-axis.
In my CSS, I've specified that on the overflow of both, they should both be able to scroll, but only the y-axis works. How would I ensure that the x-axis is scrollable also in order to see the rest of my table?
HTML:
<div id="table-wrapper-tasks">
<div id="table-scroll-tasks">
<script>
var rows = document.getElementById('dayRow').getElementsByTagName("td").length;
var cols = document.getElementById('employeeCol').getElementsByTagName("tr").length;
var rowT = null;
var drawTable = '<table class="tableTasks">';
for (let i = 0; i < rows; i++) {
drawTable += '<tr>';
for(let j = 0; j < cols; j++) {
drawTable += '<td>Testing</td>';
}
drawTable += '</tr>';
}
drawTable += '</table>';
document.write(drawTable);
</script>
</div>
</div>
CSS:
/* Settings for Tasks table */
.tableTasks {
float:right;
width:100%;
margin-top:5px;
empty-cells: show;
height:1000px;
line-height: 35px;
width: 100px;
}
#table-wrapper-tasks {
position: relative;
width:81%;
float:right;
}
#table-scroll-tasks {
overflow-x: scroll;
overflow-y: scroll;
max-height: 520px;
}
The problem is where you are specifying float property. If you remove it things should work fine.
.tableTasks {
width:100%;
margin-top:5px;
empty-cells: show;
height:1000px;
line-height: 35px;
width: 100px;
}
I have a issue after a lengthy battle with simply assigning the touch events to a image slider.
I now have a working touchscreen image slider but the only problem is that when I touchscreen the movement position begins from the center of the div and moves the whole div to be positioned with the pointer in the middle and lift off screen - and then attempt to do another movement. The movement position begins again in the center of the div.
I know I need to reset the co-ords somehow when I lift off screen, or maybe unbind, but I have no idea how to do this.
Here is a little HTML for the divs:
.container{
position:absolute;
top:0%;
left:0%;
width:500px;
height:100%;
}
.drag{
position: absolute;
top:1%;
left:0%;
width:100%;
height:15%;
-webkit-transform: translate3d(0,0,0);
border-style: solid; 2px;
border-color: blue;
z-index:1000;
}
</head>
<body>
<div id="container" class="container">
<div id='drag' class='drag'><!---video area--->
some images
</div>
</div>
Here is the code for the swipe events.
var dom = {
container: document.getElementById("container"),
drag: document.getElementById("drag"),
}
var container = {
x: dom.container.getBoundingClientRect().left,
y: dom.container.getBoundingClientRect().top,
w: dom.container.getBoundingClientRect().width,
h: dom.container.getBoundingClientRect().height
}
var drag = {
w: dom.drag.offsetWidth
}
target = null;
document.body.addEventListener('touchstart', handleTouchStart, false);
document.body.addEventListener('touchmove', handleTouchMove, false);
document.body.addEventListener('touchend', handleTouchEnd, false);
document.body.addEventListener('touchcancel', handleTouchCancel, false);
function handleTouchStart(e) {
if (e.touches.length == 1) {
var touch = e.touches[0];
target = touch.target;
}
}
function handleTouchMove(e) {
if (e.touches.length == 1) {
if(target === dom.drag) {
moveDrag(e);
}
}
}
function handleTouchEnd(e) {
if (e.touches.length == 0) { // User just took last finger off screen
target = null;
}
}
function handleTouchCancel(e) {
return;
}
function moveDrag(e) {
var touch = e.touches[0];
var posX = touch.pageX - container.x - drag.w / 2;
dom.drag.style.left = posX + "px";
}
I made a nice transition effect when switching between images, it sets the opacity to 0 (With a transition of all .5s) then .5s later (Via setTimeout) the src of the image is changed and it should fade back in.
It works fine on Chrome and IE but on firefox the image fades out and then instead of fading back to opacity:1 it just jumps straight to it.
Here is my code
Javascript:
AddEventListener(window, 'load', function () {
window.FadeinTime = 500;
var LargeImageDiv = document.getElementById('LargeImage');
window.LargeImage = LargeImageDiv.childNodes[1];
var LargeImageCaption = LargeImageDiv.childNodes[3];
var SlideText = ['Videography', 'Photography', 'Walkthroughs', 'Fine Art'];
window.Images = []; //Some image links
LargeImage.src = '/Resources/Home/' + window.Images[0];
window.AutoSlide = setInterval(function () {
var SlideNo = parseInt(LargeImage.getAttribute('data-slide')) + 1;
var SlideTextNo = parseInt(LargeImage.getAttribute('data-slideText')) + 1;
if (SlideNo == Images.length) SlideNo = 0;
if (SlideTextNo == SlideText.length) SlideTextNo = 0;
LargeImage.setAttribute('data-slide', SlideNo.toString());
LargeImage.setAttribute('data-slideText', SlideTextNo.toString());
LargeImageDiv.setAttribute('style', '-khtml-opacity:0;-moz-opacity:0;-ms-filter: alpha(opacity=0);-ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);filter: alpha(opacity=0);opacity:0;');
setTimeout(function () {
LargeImage.src = '/Resources/Home/' + Images[SlideNo];
LargeImageCaption.innerHTML = SlideText[SlideTextNo];
LargeImageDiv.removeAttribute('style');
}, window.FadeinTime)
}, 2500)
});
HTML:
<div id="LargeImage" class='NoSelect' onclick='if(event.target.nodeName == "BUTTON") return; var u = this.childNodes[3].innerHTML; window.location=(u=="Videography"||u=="Walkthroughs"?"/Videos/View/"+u:"/Pictures/View/"+u);'>
<img src="" data-slide='0' data-slideText='0'/>
<pre class='Caption'>Videography</pre>
</div>
CSS:
body > div#Content > div#LargeImage {
cursor:pointer;
max-height:490px;
min-height:300px;
width:100%;
overflow:hidden;
margin:0 auto;
position:relative;
-moz-transition:.5s;
-webkit-transition:.5s;
-o-transition:.5s;
transition:.5s;
}
body > div#Content > div#LargeImage > button {
position:absolute;
bottom:5px;
right:5px;
;
}
body > div#Content > div#LargeImage > img {
width:100%;
margin-top:-10%;
}
body > div#Content > div#LargeImage > pre {
height:50px;
font-size:80px;
}
I've been trying to make two divs stick to the top of the page after the user scrolled past these divs. Both divs are positioned at the same hight. This is what I have been using from other stackoverflow answers:
Html:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
function sticky_relocate() {
var window_top = $(window).scrollTop();
var div_top = $('#sticky-anchor').offset().top;
if (window_top > div_top)
$('#blockleft').addClass('sticky')
else
$('#blockleft').removeClass('sticky');
}
$(function() {
$(window).scroll(sticky_relocate);
sticky_relocate();
});
</script>
</head>
<body>
<div id="header"></div>
<div id="sticky-anchor"></div>
<div class="container">
<div id="blockleft"></div>
<div id="blockright"></div>
<div id="content"></div>
</div>
</body>
Css:
body {
margin: 0;
padding: 0;
}
#header {
height:200px;
background-color:#666;
}
#blockleft {
width:100px;
height:500px;
margin-top:10px;
background-color:#090;
float:left;
}
#blockright {
width:100px;
height:500px;
margin-top:10px;
background-color:#0F3;
float:right;
}
#content {
width:500px;
height:2000px;
background-color:#0CF;
margin:auto;
}
.container {
width:800px;
margin:auto;
}
.sticky {
position: fixed;
top: 0;
}
The script is working fine on one div, but when using the script twice it automatically moves the right div to the left and this one is not sticking to the top of the page.
I was hoping someone could help me out with this one.
Edit: Recreated the problem in a new document
Since the divs lose float property when we make it position:fixed, they both overlap with each other. In order to make them in their position, we need to apply right distance for the right div. To fix this, replace your script code as follows.
<script type="text/javascript">
function sticky_relocate() {
var containerWidth = $(".container").outerWidth(true);
var window_top = $(window).scrollTop();
var div_top = $('#sticky-anchor').offset().top;
if (window_top > div_top)
{
$('#blockleft').addClass('sticky');
$('#blockright').addClass('sticky');
$('#blockright').css("right", (containerWidth-800)/2 + "px");
}
else
{
$('#blockleft').removeClass('sticky');
$('#blockright').removeClass('sticky');
}
}
$(function() {
$(window).scroll(sticky_relocate);
sticky_relocate();
});
</script>
The code $('#blockright').css("right", (containerWidth-800)/2 + "px"); calculates the right distance value for the right div and adds css property right:XXXpx to that div while scrolling. The code var containerWidth = $(".container").outerWidth(true); fetches the width of the container div with its margin value (since margin is made auto, we need definite number for calculation)