I have three classes of div containers. One is an outer container
with width:1200px, with inner div rows that each have inner div's with a
desired size of 280 px. My problem is that when I create the elements
using the DOM that the CountriesInnerDiv elements are varying in size depending what is inside them.
Here's what I have so far:
.CountriesOuterDiv1{
width: 1200px;
}
.CountriesInnerDiv{
min-width:280px;
display:inline;
border:1px solid black;
}
.RowDiv {
width:100%;
}
Here is the relevant Javascript:
function AddTable() {
var TableDiv = document.getElementById("CountriesOuterDiv");
var i,j;
var NumCountries = 5;
var NumSectors = 5;
for (i = 0; i < NumCountries; i++) {
var RowDiv = document.createElement("div")
RowDiv.className = "RowDiv";
RowDiv.id = "Row"+i;
for (j = 0; j < NumSectors + 1; j++) {
var CountryData = document.createElement("div");
var SectorString = String(i+1)+"_"+String(j);
CountryData.className = "CountriesInnerDiv";
CountryData.id = "CountryData"+SectorString;
if (!((i ==0 && j == 0) || (i==0 && j ==1))) {
CountryData.style.display = "none";
}
if (j == 0 || (i == 0 && j == 1)) {
var CountryDataSelect = document.createElement("select");
var AddButton = document.createElement("button");
AddButton.id = "AddButton" + SectorString;
AddButton.innerHTML = "+";
if (j != 0) {
AddButton.setAttribute('onclick','AddOrDeleteDiv("add", "' + SectorString + '");');
}
else {
if (i != NumCountries - 1) {
AddButton.setAttribute('onclick','AddCountry("' + SectorString + '")');
}
if (i != 0) {
var DeleteCountry = document.createElement("button");
DeleteCountry.id = "DeleteButton" + SectorString;
DeleteCountry.innerHTML = "-";
DeleteCountry.setAttribute('onclick', 'DeleteCountry("' + SectorString + '")');
}
}
CountryData.appendChild(CountryDataSelect);
if (i != NumCountries - 1) {
CountryData.appendChild(AddButton);
}
if (i!=0) {
CountryData.appendChild(DeleteCountry);
}
RowDiv.appendChild(CountryData);
}
else if (j == NumSectors) {
var CountryDataSelect = document.createElement("select");
var DeleteButton = document.createElement("button");
DeleteButton.id = "DeleteButton" + SectorString;
DeleteButton.innerHTML = "-";
DeleteButton.setAttribute('onclick','AddOrDeleteDiv("delete", "' + SectorString + '");');
CountryData.appendChild(CountryDataSelect);
CountryData.appendChild(DeleteButton);
}
else {
var CountryDataSelect = document.createElement("select");
var AddButton = document.createElement("button");
var ADString = "add";
AddButton.setAttribute('onclick','AddOrDeleteDiv("add", "' + SectorString + '");');
AddButton.id = "AddButton" + SectorString;
AddButton.innerHTML = "+";
var DeleteButton = document.createElement("button");
DeleteButton.id = "DeleteButton" + SectorString;
DeleteButton.innerHTML = "-";
DeleteButton.setAttribute('onclick','AddOrDeleteDiv("delete", "' + SectorString + '");');
CountryData.appendChild(CountryDataSelect);
CountryData.appendChild(AddButton);
CountryData.appendChild(DeleteButton);
}
RowDiv.appendChild(CountryData);
TableDiv.appendChild(RowDiv);
}//End of inner for
}//End of outer for
}//end of function
Its cose you make this div display:inline; do like this .CountriesInnerDiv{
min-width:280px;
display:inline-block;
border:1px solid black;
}
Basically, what you're experiencing, is most likely that the inner element is just too big in it's minimal size to fit the parent one when the window is small... well.. we can't have an inside bigger than an outside... unless you use
overflow: scroll;
This will make the parent element scrollable so you can visualize the child by scrolling...
or...
.parent{min-width: 280px}
wich will make the parent has the same minimum width...
Related
For this assignment, the particular content needs to be in the scroll function because there's certain interactions for each scene. However, the content doesn't appear before scrolling which makes sense obviously. My question is if there is any way to get around this issue? Because I get all the content on the page except the content that sits in my scroll function.
$(window).scroll(function () {
$(".scenes").each(function (index) {
$.fn.isInViewport = function () {
var elementTop = $(this).offset().top;
var elementBottom = elementTop + $(this).outerHeight();
var viewportTop = $(window).scrollTop();
var viewportBottom = viewportTop + $(window).height();
return elementBottom > viewportTop && elementTop < viewportBottom;
};
index = index + 1
// console.log(index);
index = nummer - index * nummer / totaal;
$(this).css({
'background': 'hsl(85, 70%,' + index + '%)',
});
if ($(this).isInViewport()) {
console.log(this);
if ($(this).attr("id") == "scene1") {
ViewportCount = 1;
} else if ($(this).attr("id") == "scene2") {
ViewportCount = 2;
} else if ($(this).attr("id") == "scene3") {
ViewportCount = 3;
} else if ($(this).attr("id") == "scene4") {
ViewportCount = 4;
} else if ($(this).attr("id") == "scene5") {
ViewportCount = 5;
} else if ($(this).attr("id") == "scene6") {
ViewportCount = 6;
}
console.log($(this).attr("id") + " is visible");
} else {
console.log($(this).attr("id") + " is hidden")
}
in chrome, space-around doesn't center items if its single column.
but in Firefox, it works.
how to make it behave like firefox?
also, keep in mind that text is aligned to the right
.flex-cont {
display: flex;
justify-content: flex-start;
flex-flow: column wrap;
align-content: space-around;
align-content: space-evenly;
align-items: flex-end;
}
.flex-item {
/* display: inline-block; */
flex: 0 1 auto;
width: fit-content;
}
http://jsfiddle.net/f6k7xoe0/1/
edit: also I can do this but this messes up text aligning to right :
.flex-cont{
align-items: center;
}
edit: honestly I wouldn't care so much if it was as a hobby, but I added cefsharp(chrome) in my application. will be in production. there is no other way. i have to get that render in the cefsharp.
edit:
this is not a duplicate.
I dont ask WHY it doesn't work. I want a solution
my output is different. output in the other questions is not even multi-column.
edit2: I solved it via js getboundrect compare get max-width of each item them apply margin if wrap happens. but its messy don't wanna use it. but I have to.
I cleaned up the code to make it apply the all flex-container, flex item if you give appropriate CssSelector in the doit() function. it will work. but this is for columns.
http://jsfiddle.net/yeaqrh48/1203/
var debug = true;
class ertTimer {
constructor(funcName ,intervalms=3500, maxRunDuration=20000 , StopIfReturnsTrue=true ) {
this.intervalObj = setInterval(function(){
console.log("interval - funcName:" + funcName.name);
try{
var res = funcName();
if(StopIfReturnsTrue)
if(res == true)
clearInterval(intervalObj);
} catch(exx){console.warn(exx.message, exx.stack);}
}, intervalms);
// after 15 sec delete interval
setTimeout( function(){ clearInterval( intervalObj ); },maxRunDuration);
this.intervalms = intervalms;
this.maxRunDuration = maxRunDuration;
}
get getter_intervalms() { return this.intervalms; }
calcRepeatTimes() {
return this.maxRunDuration / this.intervalms;
}
}
var center_ONsingleCol_nonFF = function(contNode, itemSelector) {
var items = contNode.querySelectorAll(itemSelector);
//arr.count shoud be 1 element // items[0].style.alignItems = "center";
var parItem = items[0].parentNode;
var parItemR = parItem.getBoundingClientRect();
var parWidth = parItemR.width;
var maxItemWidth = 0;
for (var k = 0; k < items.length; k++) {
var currItem = items[k].getBoundingClientRect();
if (currItem.width > maxItemWidth)
maxItemWidth = currItem.width;
//console.log(parWidth, itemWidth);
}
var alignItemsVal = getComputedStyle_propValue(parItem , "align-items");
var flexDirVal = getComputedStyle_propValue(parItem , "flex-direction");
var iswrapped = isWrapped(contNode ,itemSelector );
for (var k = 0; k < items.length; k++) {
if(iswrapped && flexDirVal == "column" ){
if(alignItemsVal == "flex-end"){
items[k].style.marginRight = "" + ((parWidth - maxItemWidth) * 0.5) + "px";
items[k].style.marginLeft = "";
}
else if(alignItemsVal == "flex-start"){
items[k].style.marginRight = "";
items[k].style.marginLeft = "" + ((parWidth - maxItemWidth) * 0.5) + "px";
}else
{
items[k].style.marginRight = "";
items[k].style.marginLeft = "";
}
}
else{
items[k].style.marginRight = "";
items[k].style.marginLeft = "";
}
}
};
var getComputedStyle_propValue = function(element , CssPropName){
//var element = document.querySelector( selector );
var compStyles = window.getComputedStyle(element);
var comStyle_xxx = compStyles.getPropertyValue(CssPropName);
return comStyle_xxx;
};
var colorizeItem = function(items) {
for (var k = 0; k < items.length; k++) {
items[k].style += ";background:Red;";
}
};
var detectWrap = function(contNode, item_selector) {
var wrappedItems = [];
var prevItem = {};
var currItem = {};
var items = contNode.querySelectorAll(item_selector);
//console.log("wrapped item arrrat::",items);
for (var i = 0; i < items.length; i++) {
currItem = items[i].getBoundingClientRect();
if (prevItem && prevItem.top > currItem.top) {
wrappedItems.push(items[i]);
}
prevItem = currItem;
}
return wrappedItems;
};
var isFirefox = function() {
var _isFF = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
return _isFF;
};
var isWrapped = function(contNode, item_selector){
var wrappedItems = detectWrap(contNode, item_selector);
//colorizeItem(wrappedItems);
if (wrappedItems == null || wrappedItems.length == 0)
return true;
else
return false;
};
var isWired_listenContResize = false;
var doit = function() {
if (isFirefox()) {
console.log("ff already works Right. ");
return;
} else {
console.log("not ff. script will run. ");
}
/* flexItem_selector must be relative to flexCont*/
var flexContainer_selector = ".flex-cont.cont-resize"; /*specific flex-cont */
var flexItem_selector = ".flex-item";
var contList = document.querySelectorAll(flexContainer_selector);
for (var i = 0; i < contList.length; i++) {
//no such event //there is external lib..
// call doit after you change size in the code;
if (!isWired_listenContResize) {
contList[i].onresize = function() { doit(); };
}
center_ONsingleCol_nonFF(contList[i], flexItem_selector);
}
isWired_listenContResize = true;
};
window.onresize = function(event) { doit(); };
window.onload = function(event) {
doit();
const et1_ = new ertTimer(doit , 500, 320000,true );
};
This is an example of how we can log in chrome dev tools with colors:
console.log('%c test1 ', 'background: black; color: green')
I was wondering whether we can log with table and colors and the same time ?
There's no styling capabilities on the console.table function, as per the Console API.
However, I was able to come up with a really hacky solution for styling a console.log statement as if it were a table. This is probably not going to be good enough, but it was pretty fun to make.
There were many limitations, like not being able to set the width and height properties. My workaround was to pad the text with spaces to match the longest property name/value.
(function() {
function getProperties(obj) {
var props = [];
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
props.push(prop);
}
}
return props;
}
function getLongestTextLength(objArray) {
var longest = 0;
for (var obj of objArray) {
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
var length = Math.max(prop.length, obj[prop].length);
if (length > longest) longest = length;
}
}
}
return longest;
}
console.fancyTable = function(objArray) {
var objProto = objArray[0];
var args = [];
var header = '';
var baseStyles = 'padding: 2px; line-height: 18px;';
var baseBorders = 'border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; '
var headerStyles = baseStyles + baseBorders + 'font-weight: bold; background: lightcoral;';
var lastHeaderStyles = baseStyles + 'font-weight: bold; border: 1px solid black; background: lightcoral;';
var rowStyles = baseStyles + baseBorders + 'background: lightblue;'
var lastRowStyles = baseStyles + 'border: 1px solid black; background: lightblue;'
var props = getProperties(objProto);
var longestTextLength = getLongestTextLength(objArray);
for (var i = 0; i < props.length; i++) {
var prop = props[i];
while (prop.length < longestTextLength) {
prop += ' ';
}
header += '%c' + prop + ' ';
if (i === props.length - 1) {
args.push(lastHeaderStyles);
} else {
args.push(headerStyles);
}
}
for (var i = 0; i < objArray.length; i++) {
var obj = objArray[i];
header += '\n';
for (var j = 0; j < props.length; j++) {
var val = obj[props[j]];
while (val.length < longestTextLength) {
val += ' ';
}
header += '%c' + val + ' ';
if (j === props.length - 1) {
args.push(lastRowStyles);
} else {
args.push(rowStyles);
}
}
}
args.unshift(header);
console.log.apply(this, args);
}
})();
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
// create some test objects
var john = new Person("John", "Smith");
var jane = new Person("Jane", "Doe");
var emily = new Person("Emily", "Jones");
var peopleToLog = [john, jane, emily];
console.fancyTable(peopleToLog);
I'll make some improvements if I can, and perhaps publish it for the giggles.
I have a script set up to extract figures from a csv file into a webpage. We have a problem in that a figure that have a 0 after the decimal point is being ignored so whilst the csv file shows 1.094 when teh figure is transferred to the webpage it is 1.94
There is a js script and then an asp script that works the function
function getHTTPObject()
{
var x = null;
if (window.XMLHttpRequest)
{
x = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
x = new ActiveXObject("Microsoft.XMLHTTP");
if (!x)
{
x = new ActiveXObject("Msxml2.XMLHTTP");
}
}
return x;
}
var gobj = getHTTPObject();
window.onload=update();
function update()
{
var xpath = "ratesxtract.asp";
if (gobj) {
gobj.open("GET", xpath, true);
gobj.onreadystatechange = update_all;
gobj.send(null);
}
else {alert("XMLHTTP access problem. Please exit page and try again" ); }
}
function update_all()
{
if (gobj.readyState == 4) {
if (gobj.status == 200) {
// dobj = document.getElementById("BLastUpdated");
var A = gobj.responseText;
// dobj.innerHTML = A;
if (A == "error") {alert("XMLHTTP access problem. Please exit page and contact us" ); }
else { processfile(A); }
}
}
function processfile(A)
{
var errormess = "none";
var AA = new String(A);
AA = AA.split("$");
var nName = null;
var dobj = null;
var nValue = null;
var i = 0;
for (i = 0; i < AA.length; i++) {
if (AA[i].charAt(0) == "Z") {
nName = AA[i];
dobj = document.getElementById(nName);
}
else { nValue = "";
nValue += AA[i];
dobj.innerHTML = nValue;
}
}
if ( i == 0 ) { errormess = "failed to access exchange rates data, please exit page and try again";
alert(errormess)
}
}
ASP SCRIPT
<%#LANGUAGE='JScript'%>
<%
var sfile = Server.MapPath("forex\\ratefile.csv");
var fs = Server.CreateObject("Scripting.FileSystemObject");
var fsT = fs.OpenTextFile(sfile, 1, 0);
var xline;
var p = 0;
var q = 0;
var d = 0;
var i = 0;
var n = 0;
var t = 0;
var ts = 0;
var mname;
var mprice;
var mtime = "";
var INLine
var LN;
var cresult = "";
while(!fsT.AtEndOfStream) {
INLine = fsT.ReadLine();
xline = String(INLine);
if ( p != 0) {
LN = xline.split(",");
mname = xtrim(LN[0]);
mprice = doamount3(LN[1]);
if (p == 1) { mtime = xtrim(LN[2]); }
if (n > 0){ cresult += "$"; }
n++;
cresult += "Z" + mname + "$" + mprice;
}
p++;
}
cresult += "$ZTIM$" + mtime;
fsT.Close();
Response.Write(cresult);
%>
<%
function xtrim(x)
{
var xd = x.replace(/^\s+|\s+$/gm,'');
return xd;
}
function doamount3(amt)
{
var ZLine = String(amt);
ZLine = xtrim(ZLine);
if (ZLine.indexOf(".") == -1) {
ZLine += ".00";
return(ZLine);
}
var idata = ZLine.split(".");
var xadp = new String(idata[1]);
var xlen = xadp.length;
if (xlen == 1) {
idata[1] = xadp + "00";
ZLine = idata[0] + "." + idata[1];
return(ZLine);
}
if (xlen == 2) {
idata[1] = xadp + "0";
ZLine = idata[0] + "." + idata[1];
return(ZLine);
}
var p4 = xadp.charAt(3);
var p3 = parseInt(xadp.substring(0,3), 10);
if (p4 > 4) { p3 += 0; }
idata[1] = String(p3);
ZLine = idata[0] + "." + idata[1];
return(ZLine);
}
%>
If anyone can help be greatly appreciated
In blogspot - I found a script about this function. But I only have 25 posts per label, I want more posts such as 100 or 200 posts per label.
This is script
<div class='rbbox'>
<h7>CÁC CHAP TRONG BỘ TRUYỆN</h7>
<div id='albri'/>
<script type='text/javascript'> var homeUrl3 = "
<data:blog.homepageUrl/>"; var maxNumberOfPostsPerLabel; var maxNumberOfLabels; maxNumberOfPostsPerLabel = 100; maxNumberOfLabels = 1; function listEntries10(json) { var ul = document.createElement('ul'); var maxPosts = (json.feed.entry.length <= maxNumberOfPostsPerLabel) ? json.feed.entry.length : maxNumberOfPostsPerLabel; for (var i = 0; i < maxPosts; i++) { var entry = json.feed.entry[i]; var alturl; for (var k = 0; k < entry.link.length; k++) { if (entry.link[k].rel == 'alternate') { alturl = entry.link[k].href; break; } } var li = document.createElement('li'); var a = document.createElement('a'); a.href = alturl; if(a.href!=location.href) { var txt = document.createTextNode(entry.title.$t); a.appendChild(txt); li.appendChild(a); ul.appendChild(li); } } for (var l = 0; l < json.feed.link.length; l++) { if (json.feed.link[l].rel == 'alternate') { var raw = json.feed.link[l].href; var label = raw.substr(homeUrl3.length+13); var k; for (k=0; k
<100; k++) label = label.replace("%20", " "); var txt = document.createTextNode(label); var h = document.createElement('b'); h.appendChild(txt); var div1 = document.createElement('div'); div1.appendChild(h); div1.appendChild(ul); document.getElementById('albri').appendChild(div1); } } } function search10(query, label) { var script = document.createElement('script'); script.setAttribute('src', query + 'feeds/posts/default/-/' + label + '?alt=json-in-script&callback=listEntries10'); script.setAttribute('type', 'text/javascript'); document.documentElement.firstChild.appendChild(script); } var labelArray = new Array(); var numLabel = 0;
<b:loop values='data:posts' var='post'>
<b:loop values='data:post.labels' var='label'> textLabel = "
<data:label.name/>"; var test = 0; for (var i = 0; i < labelArray.length; i++) if (labelArray[i] == textLabel) test = 1; if (test == 0) { labelArray.push(textLabel); var maxLabels = (labelArray.length <= maxNumberOfLabels) ? labelArray.length : maxNumberOfLabels; if (numLabel < maxLabels) { search10(homeUrl3, textLabel); numLabel++; } }
</b:loop>
</b:loop>
</script>
<script type='text/javascript'>RelPost();</script>
</div>
I changed maxNumberOfPostsPerLabel = 100; but it's still display only 25 posts, Can someone help me about this ? I really need to show more posts :(
Here is my web link : http://manga.mystown.com/2015/08/juji-itou-horror-collection-chap-39.html