JavaScript - Change Height Of Div Using Javascript
Hey guys, so i have a comment section.
And what i want to do is if the height of the comment box is larger then lets say 100px. I want to set the height of the comment box to 50px and then display a "read more" button. And this read more button would toggle and allow the height to be "auto" and not set to 50px. so my html would look like this Code: <div class="comment-section"> <div class="comment"><p>This is where text would go. </p></div> <div class="read-more">Read More</div> </div> I have the class "read-more" set to "display:none" How would i do this? This is what i have / was trying and have been unsuccessful Code: <script type="text/javascript"> $(function(if ($".comment".style.height > 100px;){ { $".comment".style.height = 50px; $".read-more".style.display = block; } }); </script> Similar TutorialsI just placed this div named iframe_container in a table cell. There's an iframe and another div inside of it and when I went to fine tune the alignment I discovered I could change the width of the div but not the height I can set it to 200 or 1000, it doesn't make the slightest difference. It seems to be clinging to the outside of the iframe. I can make it bigger by inserting breaks after the iframe but then the compass_rose div loses its absolute position for some reason I searched the page for height tags that might be interfering with this but I've turned up squat. I took the height specs off the table but still no effect. Can anyone spot the problem? <td style="width: 800px; height: 700px" valign="top" class="style3" align="left"> <div id="iframe_container" style="width:1000px; height=700; position: relative; overflow-x:auto; overflow-y:hidden"> <div id="compass_rose" style="top: 5px; left: 1200px; position: absolute; z-index: 2; visibility:visible;"><img alt="Compass Rose" src="compass_rose_animated2.gif" width="80" height="80" /></div> <iframe id="viewer" width="1600" height="635" src="front_page2.jpg" marginwidth="1" marginheight="1" name="viewer"></iframe> </div> </td> </tr> </table> I'm developing a site for my wife's acupuncture practice (http://www.acupunctuurfengyun.be. Since I have two monitors (one wide screen, one square) attached to my computer I can verify how it will look in different resolutions. While doing so I came across a nasty thing: in some resolutions the content div is very small and not using all of the full browser window (left after the header section). Is it possible to make a change to the CSS min-height and max-height while the page is being loaded? I've looked into lots of samples but all depend on a click or mouse over event and didn't want to work with onload in the body tag. I've also thought about putting the stuff in the PHP part of my code but I am lost at this moment on how to do this. Could someone help me out here? I am trying to customize this scrollbar so that it will fit all screen resolutions and I was wondering how I could do this by somehow customizing the JavaScript files created by Nathan Faubion or if I could do this using other JavaScript variables (var widthPercentage) to change the pixels to percentages? Please let me know what you think. Thank you very much! One of the pages on the website I'm using the JavaScript on: http://www.clintshipley.com/about.html Code: JavaScript file jsScroller.js: //Created by Nathan Faubion http://www.n-son.com/scripts/jsScrolling/ function jsScroller (o, w, h) { var self = this; var list = o.getElementsByTagName("div"); for (var i = 0; i < list.length; i++) { if (list[i].className.indexOf("scroller-content") > -1) { o = list[i]; } } //Private methods this._setPos = function (x, y) { if (x < this.viewableWidth - this.totalWidth) x = this.viewableWidth - this.totalWidth; if (x > 0) x = 0; if (y < this.viewableHeight - this.totalHeight) y = this.viewableHeight - this.totalHeight; if (y > 0) y = 0; this._x = x; this._y = y; with (o.style) { left = this._x +"px"; top = this._y +"px"; } }; //Public Methods this.reset = function () { this.content = o; this.totalHeight = o.offsetHeight; this.totalWidth = o.offsetWidth; this._x = 0; this._y = 0; with (o.style) { left = "0px"; top = "0px"; } }; this.scrollBy = function (x, y) { this._setPos(this._x + x, this._y + y); }; this.scrollTo = function (x, y) { this._setPos(-x, -y); }; this.stopScroll = function () { if (this.scrollTimer) window.clearInterval(this.scrollTimer); }; this.startScroll = function (x, y) { this.stopScroll(); this.scrollTimer = window.setInterval( function(){ self.scrollBy(x, y); }, 40 ); }; this.swapContent = function (c, w, h) { o = c; var list = o.getElementsByTagName("div"); for (var i = 0; i < list.length; i++) { if (list[i].className.indexOf("scroller-content") > -1) { o = list[i]; } } if (w) this.viewableWidth = w; if (h) this.viewableHeight = h; this.reset(); }; //variables this.content = o; this.viewableWidth = w; this.viewableHeight = h; this.totalWidth = o.offsetWidth; this.totalHeight = o.offsetHeight; this.scrollTimer = null; this.reset(); }; JavaScript on HTML page: <script type="text/javascript" src="Scripts/jsScroller.js"></script> <script type="text/javascript" src="Scripts/jsScrollbar.js"></script> <script type="text/javascript"> var scroller = null; var scrollbar = null; window.onload = function () { scroller = new jsScroller(document.getElementById("scroller"), 550, 275); scrollbar = new jsScrollbar (document.getElementById("scrollbar-content"), scroller, false); } </script> I am struggling to find a solution that enables me to have a div that is a certain percentage height of the window and then when the user is using a different resolution, it remains at that percentage of the screen height - not going off of the bottom as I have a fixed percentage no scroll full background image. I have sorted it for width but can't get it to work for height. any ideas? lol Bee x Hi guys, was just wondering if there was a way to control the page height and width using js/jquery? I have a page that is: width: 980px height: 2500px I would like the page height to be set to around 900px with the viewable scrollbar and all other content not viewable underneath. Any help is appreciated Cheers, paffley Hi, well earlier i asked for a script which can load game which showing some banner until the game is loading and the load progress that it shows, it shouldn't be fake, many people said you need flash for it, but atlast i found a script that can do that for me. BUT there is a issue when i started using the script in the script the width and height can be in px like width 500 but it can't be made to width 100% when i make it 100% the script stops working. I can't use px or any other thing except 100% as i want the flash to increase its width and height with the change in screen resolution. Here is the script, you can make a demo html file out of it for testing purposes, if you don't want to make one i am ready to provide a demo page too, please leave a comment for it. Thank you ^_^ Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Pre-roll Example page</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script type="text/javascript" src="http://files.cryoffalcon.com/woro/preroll.dev.js"></script> <style> .gamecontent {width:923px;padding:0px;margin:0px auto 0px auto;background-color:#FFF;} .gamecontent .gamewrapper {margin:0px auto 0px auto;} .gamecontent .game {float:left;margin:0px auto 0px auto;padding:0px;overflow:hidden;width:1px;height:1px} .gamecontent .ad {display:none;width:300px;height:300px;margin:0px auto 0px auto;padding:50px auto 0px auto;text-align:center;font-size:10px} .gamecontent .ad #progress {width:200px;height:10px;margin:10px auto 0px auto;padding:0px;border:solid 1px #E7B9D1;text-align:left;} .gamecontent .ad #pbar {width:0px;height:10px;background-color:#CCC;} .gamecontent .ad #pskip {text-align:center;} .medrectangle {width:300px;height:250px;border:none} </style> </head> <body> <div class="gamecontent"> <div class="gamewrapper" style="height:640px;width:640px;"> <div class="game" id="gameframe"></div> <div id="adframe" class="ad"> <div>Advertisement</div> <div id="plad"></div> <div id="progress"></div> </div> <noscript> <div> <!--Game embed code should be placed here here--> </div> </noscript> </div> </div> <script type="text/javascript" language="javascript"> var af = 'adframe'; var gf = 'gameframe'; var gid = 'gameswf'; var adinvoke = '<iframe class="medrectangle" src="<!--to show my logo or ad-->" scrolling="no"></iframe>'; function skipad() { $('#plad').html('<div></div>'); $('#'+af).hide(); $('#'+gf).css('width','640px'); $('#'+gf).css('height','640px'); } $('#gameframe').preloadad( { // calls the init method swf : 'http://games.balloontowerdefense.net/b/balloon_tower_defense_4_expansion.swf', width : 640, height : 640, gameid : gid, gameframe : gf, adframe : af, adcode : adinvoke, pltime : 10000, gametype : 'swf', base :'http://games.balloontowerdefense.net/b/', skiptxt : 'Click here to show the game', showad :'1' }); </script> </body> </html> in the above code the 640 width and height is the issue, as it doesn't work with 100% values, i was wondering how to make it work with 100% width and height. I don't know what did i miss or where did i go wrong? I need javascript to read height of an static multiline text and write height value into the var value? Is it possible? I was told by Kunena developers that the issue is that when I insert an image or a video in my forum, it is loading after javascript loads setting the height to "static". Unfortunately they didn't know a fix, so I came here I guess the script is causing the forum articles to overflow the height by exactly the same number of pixels as the image/video. When the page is reloaded, the issue is corrected, but its really annoying for visitors who don't know to reload the page. Not to sound like a big dummy or anything, but I have gone through every file in my template and have found absolutely no "static" scripts, so any help in tracking it down would be greatly appreciated as I am not a javascript guru. I have tried preloading the images, but it had no effect. An example of the overflow issue can be found here https://christian-knowledge.com/inde...id=22&id=25#25 At the moment I have changed the overflow value on that particular section to "auto" to get around it for the time being, but its definitively not a good fix. Thank you for your time and I really appreciate any assistance or advice on how to fix this Hi there. I'm relatively new to coding in javascript, so I'm hoping that some kind souls could help me out! I'm trying to make an animated image height changer (example: changing an image's height from 50px to 500px). I'm working on a new web site using HTML5 and want to add some Flash-like animation to my page using javascript and <canvas>. The animation would only need to "play" one time once the web page has loaded. No looping is required and no user interaction (ie mouseovers, etc) is needed. Any help would be greatly appreciated. If anyone knows of similar examples online please send me a link. If you're interested in helping, please let me know if more information is needed. Thanks. Hi, When is a java script change in Production server,do we need to force the web users to clear their cache... Or is there any better way of doing it apart from using no cache header in HTML Hi can you change this javascript for me please -------------------------------------------------------------------------- -------------------------------------------------------------------------- Code: <script type = "text/javascript"> function LogIn(){ loggedin=false; username=""; password=""; username=prompt("Username:",""); username=username.toLowerCase(); password=prompt("Password:",""); password=password.toLowerCase(); if (username=="guest" && password=="login") { loggedin=true; window.location="home-page.html"; } if (username=="guest2" && password=="login2") { loggedin=true; window.location="home-page2.html"; } if (loggedin==false) { alert("Invalid login!"); } } </SCRIPT> ---------------------------------------------------------------------------------------------------------------------------------------------------- Can someone change this script to instead of prompts i would like two text boxes and a button to login p.s There is also a different bit but thats for the button if you need this part then please ask Hello. I am trying to create a javascript function which when declaring a new object, would give it properties. I'll try and show what I am doing with some code, then explain it. Code: <script type="text/javascript"> var Draggable = { Create: function(e, options) { newStyle(e, options); } }; function newStyle(destination, options) { for (x in options) { document.getElementById(destination).style.x = options[x]; } } new Draggable.Create('text', options = {border: "1px solid red"}); </script> <div id="text">Text</div> With this code, I am trying to create a new instance. I am then trying to change the border of the div with the id of "text". I know doing .style.x is what is breaking, but I'm not sure how to make it so the x will, work or to return that back to the Create function and work with it there? Any help would be appreciated. Thanks. I want to create a table in javascript with a predefined height and width and put html code in its td. I wanna know when i should stop writing html code when my table have reached the predefined height. Is there any way to do that? I started by doing this : var srcTable = document.createElement("table"); srcTable.border = 1; srcTable.borderColor = "Black"; srcTable.height = 768; srcTable.width = 1024; var tmpRow = null; var tmpCell = null; for (i = 0; i < rowCount; i++) { tmpRow = AppendRow(srcTable) for (j = 0; j < colCount; j++) { tmpCell = AppendCell(tmpRow); tmpCell.innerHTML = document.getElementById("div").innerHTML; tmpCell = null; } tmpRow = null; } The html code in "div" element is way big then 768 px. I wanna know how to loop over and break it when table reaches 768 px height. Hello! I am playing with CSS3 transitions to show/hide a DIV element. The application will be for a newsletter which will allow a user to show and hide article content. There will be multiple articles. I have a <DIV id="article1" class="content"> and the default height is 0px. When someone clicks the "show/hide article" link I set the height to 250px. A CSS transition on the content class (height) adds a smooth change from 0px to 250px. I have rigged up a simple Javascript function so that when someone clicks the "show/hide article" link, it checks the height of the DIV. If the div is 0px, it should expand the content, if not, it should shrink it. It works when you click the link the first time (i.e. the content div height is set to 250px and the transition works). But when you click it again, it does not set the height to 0px in order to hide the content. I think there is something wrong with the validation of document.getElementById(articleID).style.height ? Any ideas? Thank you! Code: Code: <!DOCTYPE html> <html land="en"> <head> <script language="javascript" type="text/javascript"> function showhideContent(articleID) { if(document.getElementById(articleID).style.offsetHeight = '0px'){ document.getElementById(articleID).style.height = '250px'; } else{ document.getElementById(articleID).style.height = '0px'; } } </script> <style type="text/css"> p { margin:10px; font-size:12px; } h1 { margin:10px; } body { background-color:lightgrey; font-family:Arial; font-size:12px; } #newsletter { width:500px; border:solid; border-width:1px; border-color:black; background-color:white; text-align:left; font-size:11px; } #header { height:125px; } #footer { height:50px; background-color:#330033; } #headerbar{ background-color:lightblue; height:35px; overflow:hidden; font-size:12px; -webkit-transition: background-color 1s; } #headerbar:hover{ background-color:#3399FF; } .content{ background-color:white; height:0px; overflow:hidden; -webkit-transition: height 0.5s ease-in-out; } #expand{ background-color:red; } </style> </head> <meta charset="UTF-8"> <body> <center> <div id="newsletter"> <section id="header"> <img src="newsletter_header_test.jpg"> </section> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sed turpis augue, nec cursus metus. Proin dictum, velit vel vulputate vulputate, ante sem iaculis risus, at faucibus nibh tellus et ante. Vivamus quis enim nec arcu dictum molestie non quis ipsum. <br><br> Proin vel mi eget sapien tincidunt pretium et non eros. Nullam vitae lacus at tortor volutpat feugiat. Vivamus venenatis risus in urna aliquet laoreet tempus diam consequat. Praesent viverra placerat venenatis. Quisque arcu nisl, congue sed blandit ut, suscipit eu velit. Nam quam massa, sollicitudin et elementum at, tempus nec eros. Etiam eget tortor condimentum metus accumsan dignissim eu sed sem. </p> <article> <section id="headerbar"> <div style="float:left;"> <h1>Introducing: the first article</h1> </div> <div style="float:right;"> <p> <a id="expand" href="#" onClick="javascript:showhideContent ('article1');return false;">Show/Hide Article</a> </p> </div> </section> <div> <section id="article1" class="content"> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sed turpis augue, nec cursus metus. Proin dictum, velit vel vulputate vulputate, ante sem iaculis risus, at faucibus nibh tellus et ante. Vivamus quis enim nec arcu dictum molestie non quis ipsum. <br><br> Proin vel mi eget sapien tincidunt pretium et non eros. Nullam vitae lacus at tortor volutpat feugiat. Vivamus venenatis risus in urna aliquet laoreet tempus diam consequat. Praesent viverra placerat venenatis. Quisque arcu nisl, congue sed blandit ut, suscipit eu velit. Nam quam massa, sollicitudin et elementum at, tempus nec eros. Etiam eget tortor condimentum metus accumsan dignissim eu sed sem. Quisque ultricies volutpat mauris, nec cursus <br><br> sapien laoreet ut. Maecenas volutpat porta enim et tincidunt. Sed vel lectus eget dolor dictum ultrices in in mauris. Praesent laoreet velit vitae est vulputate a varius lorem eleifend. </p> </section> </div> </article> <br> <br> <section id="footer"> <p>footer</p> </section> </div> </center> </body> </html> I need a JavaScript image changer like this: When you mouse over photo1.jpg, it will change to photo2.jpg. When you mouse over photo2.jpg it will change to photo 3.jpg and so on untill photo5.jpg. Please keep this in JavaScript form :) I currently have a web site in which I am using some Javascript to change the Background of a DIV. The DIV is defined as follows : <div id="outerscreen"> <div id="mainscreen"> </div> </div> and the Javascript I am using is as follows : var docEl = document.getElementById('outerscreen'); docEl.style.backgroundImage = "url('pics/intro.gif')"; My problem arises where this function works perfectly on IE but fails for Chrome, FF and Safari. Can anyone shed any light on what the problem is and how I might be able to resovle this. Thanks in advance Chris Here's the code that I'm working with: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type ="text/javascript"> function HouseSel(){ document.getElementById("HouseSelect").value = '3' alert (document.getElementById("HouseSelect").value); } </script> </head> <body> <form action="https://www.paypal.com/us/cgi-bin/webscr" method="post" name="_xclick"> <select name="item_name" id="HouseSelect"> <option value="0" selected="selected">--Please Select a House--</option> <option value="1">Nags Head</option> <option value="Rent Deposite: Calib ">Calibre</option> </select> <input name="calculate3" type="button" id="calculate3" tabindex="2" onclick="HouseSel(); " value="Calculate"/> </form> </body> </html> But it's still returning the initial value. How do I get it to 3? I have a javascript that randomly displays a different quote on my website. I have the quote programmed in, and they show up, but the text is tiny. I need help making the text bigger. I am a beginner at this, so i would appreciate help. This is the code: Code: <script language='JavaScript'> function random_content(){ var mycontent=new Array() mycontent[1]='Repent! The end is coming! Were out of chips!' mycontent[2]='I WANT, TO EAT, A DINOSAUR.' mycontent[3]='Last night I lay in bed looking up at the stars in the sky and I thought to myself, where the heck is the ceiling.' mycontent[4]='IT\'S A TRAP!' mycontent[5]='tardo power,activate!' mycontent[6]='LMS if ur gay' mycontent[7]='1,2,...5!' mycontent[8]='Box O Digletts' mycontent[9]='Justice is best served cold, with a side of ranch dressing' mycontent[10]='umm...I got nothing...awkward' mycontent[11]='Once you visit you can never leave' mycontent[12]='50% CaCow' mycontent[13]='almost racist free!' mycontent[14]='The last thing I want to do is hurt you. But it\'s still on the list' mycontent[15]='BOOM! Left turn!' mycontent[16]='Redrum' mycontent[17]='If 4 out of 5 people SUFFER from diarrhea... does that mean that one enjoys it?' mycontent[18]='Never, under any circumstances, take a sleeping pill and a laxative on the same night' mycontent[19]='the beginning of the end' mycontent[20]='Flaming fireballs Batman!' mycontent[21]='gotta catch em\' all' mycontent[22]='for the african children!' mycontent[23]='One sexy thang' mycontent[24]='It\'s Tardolicious!' mycontent[25]='That\'s no moon!' mycontent[26]='Caboose is god?' mycontent[27]='MLIT' var ry=Math.floor(Math.random()*mycontent.length) if (ry==0) ry=1 document.write(mycontent[ry]) } random_content() //--> </script> Hi, On my website I use CSS Fixed Positioning, but unfortunately on many mobile devices in particular this doesn't work I'd like to be able to turn these into static (e.g. Go to bottom of page) on some devices, but I'm a bit stuck (The Div btw is called apDiv2) So far I've got Code: if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod' || navigator.platform == 'BlackBerry') { $("#apDiv2").css("position", "static"); }; but no dice. Does anybody know what I'm doing wrong? The full css file is at http://atomicbuilds.com/general.css Thanks, Ed P.S. Eventually I'd also like to change the actual positioning so -142px goes to 0px, so if anybody knows that that'd be great, but I'm more worried about this first I have several checkboxes with labels, all laid out in a table. All of the checkboxes have a class of "hide" and through CSS I have them hidden. Then with javascript it's set up so that when a user clicks on the label for the checkbox the background of the TD that contains it changes colors to indicate that that item is selected. Works great except for those browsers that have javascript disabled. Then the form is useless. I'm thinking now it would be better to use javascript to apply the "hide" class to the checkboxes. That way if it's disabled then the checkboxes will still be visible and the form useable. I'm just not sure how to go about doing that (not much of a javascript ninja). Can anyone advise me on how to do that? I'd really appreciate the help! Thanks! |