July 1, 201412 yr Hi. I am not going to pretend to know anything about Java as I don't. I downloaded a free countdown script which displays yellow boxes that counts down to a specific date and time in years, months, weeks, days, hours, minutes and seconds. Trouble is, in the script I can only find one section to adjust the size and it seems to be a fixed number... ie.. width = 800 and height = 150. This obviously relates to pixels. however... My countdown is inside a div section which changes size depending on the viewers browser size. Is there a way of making this script get larger and smaller varying with the size of the div section that its in? I tried entering = 100% but it don't work. Below is the full .js file. var CountdownImageFolder = "images/"; var CountdownImageBasename = "flipper"; var CountdownImageExt = "png"; var CountdownImagePhysicalWidth = 41; var CountdownImagePhysicalHeight = 60; var CountdownWidth = 800; var CountdownHeight = 150; var CountdownLabels = { second : "SECONDS", minute : "MINUTES", hour : "HOURS", day : "DAYS", month : "MONTHS", year : "YEARS" }; var CountdownInterval = 76; There is a bit more under but this seems to be all the variable stuff. Any helpers??Thanks, Steve
July 1, 201412 yr You can find out the browsers width using Javascript here is a brief snippet of code that you can use http://www.w3schools.com/JQuery/css_width.asp you can grab the width of the users browser and then use % of that to display the blocks etc
July 1, 201412 yr Author Ji Junior. Thanks for your reply. I think I kind of understand it, but don't know how I would input it or customise it to my needs. Also that link seems to work by reading the div taft, the div that the script is in is <div id="page"> Can you help me in how I would customise it to what I need and how would it look?
July 2, 201412 yr You can set your variables value based on the screen size by checking inner width. Replace var CountdownWidth = 800; var CountdownHeight = 150; With var myWindowWidth = window.innerWidth; //big browser windows if (myWindowWidth>800) { var CountdownWidth = 800; var CountdownHeight = 150; } //small browser windows else{ var CountdownWidth = 300; var CountdownHeight = 100; } The entire countdown-function is likely to be called when the page loads so this does not work if the window is resized after the page is loaded. But you can call the function on resize as well if you want: window.onresize = function(){ yourCountdownFunction(); }
July 3, 201412 yr @@Nillervision Have you ran into issues with innerWidth? I find that it's not entirely accurate, i.e. it doesn't match my css media querys. I found a way around it by creating a ghost element and changing a css property with each breakpoint then used js to check that css property to determine which breakpoint we lie in. It works well, but I am curious as to why innerWidth is not accurate and if you know of a solution?
July 3, 201412 yr @@Nillervision Have you ran into issues with innerWidth? I find that it's not entirely accurate, i.e. it doesn't match my css media querys. I found a way around it by creating a ghost element and changing a css property with each breakpoint then used js to check that css property to determine which breakpoint we lie in. It works well, but I am curious as to why innerWidth is not accurate and if you know of a solution? Good point. I believe innerWidth is the elements width without padding and borders. For exact mesurement of elements it might be better to use body.offsetWidth which I believe returns the width including borders/padding. If you are using jQuery you can just use the width() method. Edited July 3, 201412 yr by Nillervision
July 4, 201412 yr Ive used outerWidth() to good effect it adds padding and borders. I was think of issues with getting the width of the viewport.. I guess getting the width of the body element could suffice, will have to test and see
Create an account or sign in to comment