JavaScript - On Reach Anchor Point...
Hey,
I was wondering if it is possible to make an image change whenever an anchorpoint on my page reaches the center or the side of the screen... Thanks for your help! Similar TutorialsHi guys, Having a little bit of trouble with a site I'm currently working on... I'm using some AJAX for the instant g-mail/facebook style navigation, you know the kind, with no refreshes, etc. Problem is, to allow for back/forward and bookmarks, I currently use a URL that looks like: http://www.mySiteOfFun.com/index.html#page=news.html; This is fine, not a problem... The issue comes into play when I want to open up the news.html page, from my home.html page, and have it open to news item #6 (for example). I can't add a #, because one is already being used to reference the anchor for the content div. Has anyone run into a similar problem before? If so, how did you resolve it? Can some jQuery be used to find the location of the news item div in question, on load, and scroll to it like that? Just not sure how to progress really, and any help would be greatly appreciated! 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. Hi im wanting to know how does the computer know whos scored more in a game? Thanks, Paul I am well versed in ActionScript and I have done a lot of this already in As3.0 using XML Node Object. However my client wants this application to be more friendly with iphones/ipads. So we are going to have to restart this and go with Javascript which we know very little about. Basically the internet application is going to be a 'Build your own Itinerary' for a huge rock event, where we have to sort each band selected by the user based on [Date:4th or 5th of July] and [Time Playing]. Those are the only two nodes we need to check, the [date] is obviously going to split it into two groups, and the [Time] is when the band is playing in that group and there will need to be an if/then to check for conflicts. other nodes like [Name] would be used to just add each of the bands selected to that list with .append() I guess. And [Stage] is a somewhat irrelevant node stored and displayed with each item. So. In the professional opinion of those on this board... Where is a good place for a group of 'AS3.0 wise guy hacks' to start cracking at this with JavaScript? What would you suggest for rookies like us making an emergency jump to HTML/Javascript? Thanks so much in advance for the assistance. Hello I need to do a portfolio of paintings and i found a site similar of what i have in mind. The site is http://www.pikaboo.be/ It's great because its using javascript only. I just don't know how to start my reserach for that transitions and moving objects and that stuff Anyone can give me a few tips on how to start? I have been looking at jquery and mootools it does some stuff taht it's on this site but the movement of objects and the way as they appear on the screen one by one and all that pretty stuff i have no idea how to search. Anyone can help me on where to start and how to do something like this? THank you I read somewhere (I think from Douglas Crockford) that void is a completely useless operator. What is its actual purpose? Is there anything it's good for? I see lots of javascript:void(0) hyperlinks all over the place. From what I gather, it just disables the link's default behavior...buy why not just make the href="#" or return false from an onClick handler? Can anyone enlighten me? Hello all, How to set decimal point in javascript ? e.g. var num1=23.12345; I want output as 23.12 How can i do this ? Please, guide me. Thanks function below will output price value in text field based on drop-menu option. It's working but I want it's always show value in 2 decimal point for variable 'price'. Can anyone help me with this problem? function findPrice() { if (document.getElementById("region").value == "blank") { var price = document.getElementById("price"); price.value = "<?php echo 'Choose your region to get the price'; ?>"; } if (document.getElementById("region").value == "Peninsular Malaysia") { var price = document.getElementById("price"); price.value= '<?php echo $PM_Price; ?>'; } if (document.getElementById("region").value == "Sabah/Labuan") { var price = document.getElementById("price"); price.value = '<?php echo $SL_Price; ?>'; } if (document.getElementById("region").value == "Sarawak") { var price = document.getElementById("price"); price.value = '<?php echo $SR_Price; ?>'; } } Someone please point me in the right direction. Basically what i'm trying to do is, Post up a nice image map up top of a page with several diff images (all same dimensions), and when the user clicks on one of the images, it loads down in a section below, without reloading the page. I have drawn a small diagram to show you guys what i'm talking about. So far, all I've found, are scripts that use some sort of lightbox that covers the entire page. I would like to try to stay away from flash if I can. The main browser, does'nt necessarily have to be one big image with a map, but it would make it look so much better if it looked matched the games menu. I'm trying to replicate a stats game menu, inside my webpage, so ppl can browse just like they do in game. Example: What I'm trying to replicate: When a weapon on this menu is clicked, it loads up on the right, and gives a brief description. I"m just trying to replicate the functionality of this menu really. So are there any kind of scripts out there that already exist, where I could accomplish this? or how would i go about this. just need someone to point me in the right direction. Thanks a million ok i need a bit of advice.. I have a webpage and i want to put a section of another website on to my own website.. i have a www.bebo.com profile and i only want to show the comment section on my website.. my profile is www.bebo.com/thegaadiscos is there a way to only show the comments div of the bebo site on my own website? What i want is a bit like the face book section of this website http://www.alexandraburkeofficial.com/ How would this be done does anyone know.. Hi, So, i'm using the jkpanel dropdown script in my functional prototype to show context-sensitive design notes for our integrators. it's pretty cool, but i have an implementation question .. i have many source html files that call the jkpanel script, and each page requires unique content to be loaded into the dropdown panel .. but, what i see is that the drop-down content html file is hard-coded in the .js file. in other words, i need to create a .js 'and' and html for every different set of content i want to load into the dropdown panel .. so, if i have 12 html files to hold the drop down content, i also have to create 12 different versions of the .js file to point to them .. this seems like overkill .. is there a way to always point to the same jkpanel.js file in my <head>, but load a different html file to populate its content? Thanks! RL Hi. I am trying to make one small modification to a website. I just want to make an image that, when clicked, scrolls to a certain point. Pleeeeeeaaaaaase help! This is the javascript that I think controls the scrolling: var element_y; var swiffy; var cur_groupid; var group_sortable = new Array(); var lightbox; var content; window.addEvent('load', function() { checkScrollerWidth(); checkImages(); }); function checkImages() { var check_w = window.getSize().x + 500; var winh = window.getSize().y; var divs = $$('.single_image_holder'); for(var i=0; i<divs.length; i++) { if(divs[i].getChildren().length) continue; if((parseInt($('main_images').getPosition().x) + parseInt(divs[i].get('xpos'))) >= check_w) return; var img = new Element('img', { 'src': divs[i].get('source') }); divs[i].adopt(img); } } window.addEvent('resize', function(){ checkScrollerWidth(); }); function checkScrollerWidth() { if($('scrollbar2') && $('content2') && $('handle2')) makeScrollbar( $('content2'), $('main_images'), $('scrollbar2'), $('handle2'), true); } function makeScrollbar(content,checkContent,scrollbar,handle,horizontal,ignoreMouse){ if(checkContent.getScrollSize().x < scrollbar.getSize().x) { handle.setStyle('display','none'); return; } handle.setStyle('display','block'); var steps = (horizontal?(content.getScrollSize().x - content.getSize().x)content.getScrollSize().y - content.getSize().y)) var slider = new Slider(scrollbar, handle, { steps: steps, mode: (horizontal?'horizontal':'vertical'), onChange: function(step){ var x = (horizontal?step:0); var y = (horizontal?0:step); content.scrollTo(x,y); checkImages(); } }).set(230); if( !(ignoreMouse) ){ $$(content, scrollbar).addEvent('mousewheel', function(e){ e = new Event(e).stop(); var step = slider.step - e.wheel * 30; slider.set(step); }); } } hello! i am new here and i want help! i have a problem with the scrollbar. i want to stay in a certain point after click in a onclick event. this is not happened and my scroll bar goes on the top of my page. what i can do? my code is this: <a><xsl:attribute name="href">#</xsl:attribute> <xsl:attribute name="onClick" ><xsl:text>displaybody('</xsl:text><xsl:value-of select="fileDesc/sourceDesc/@n"/><xsl:text>')</xsl:text></xsl:attribute><div id="a" onclick="definesearchmode()" align="center"><b>click here.</b></div> </a> the function displaybody shows me what i want to see and the definesearchmode() has a code to hide the phrase (click here) when you click there. thank you. How to fix a infowindow or a info template to a point so that when i drag the map the infowindow will no change place or move ...what is the code...and where shld i place it at? this is my code : var stX = "23319.3347409758"; var stY = "28825.7191286444"; var pt= new esri.geometry.Point(stX,stY,map.spatialReference); //var strImage = "http://www.rw-designer.com/i/download48b.png"; var symbol = new esri.symbol.PictureMarkerSymbol(strImage, 25,25); var attr = {"PlaceName":"Peranakan musem of Singapore","PlaceAddr":"addr"}; var infoTemplate = new esri.InfoTemplate(); infoTemplate.setTitle("Building Name:"); infoTemplate.setContent(getInfoContent); var graphic = new esri.Graphic(pt,symbol,attr,infoTemplate); gLayer.add(graphic); } function getInfoContent(graphic){ var bc = new dijit.layout.BorderContainer({style: "font-size: 11pt; height: 520px; width:493px; background: #CCFFFF;"}); var c1 = new dijit.layout.ContentPane({ region: "top", style: "height: 20px width: 100%", content: "hello" }); bc.addChild(c1); //make a tab container var tc = new dijit.layout.TabContainer({ region: "center", style: "height: 65%; width: 100%; " }, dojo.create("div")); //display attribute information var cp1 = new dijit.layout.ContentPane({ //style: " background-color: red; ", title: "<font color= #E4287C><b>detail</font> ", content: "sfdfsdfsdf" }); tc.addChild(cp1); bc.addChild(tc); return bc.domNode; } dojo.addOnLoad(addSymbol); Hey all, I am having issues with below script. Firebug returns: form[0] is undefined [Break on this error] $(form[0].elements).each(function() { I have this under my form: <script> var thisForm = $('#validateForm'); thisForm.validation(); </script> Code: (function($) { /* Validation Singleton */ var Validation = function() { var rules = { email : { check: function(value) { if(value) return testPattern(value,".+@.+\..+"); return true; }, msg : "Enter a valid e-mail address." }, url : { check : function(value) { if(value) return testPattern(value,"https?://(.+\.)+.{2,4}(/.*)?"); return true; }, msg : "Enter a valid URL." }, required : { check: function(value) { if(value) return true; else return false; }, msg : "This field is required." } } var testPattern = function(value, pattern) { var regExp = new RegExp("^"+pattern+"$",""); return regExp.test(value); } return { addRule : function(name, rule) { rules[name] = rule; }, getRule : function(name) { return rules[name]; } } } /* Form factory */ var Form = function(form) { var fields = []; $(form[0].elements).each(function() { var field = $(this); if(field.attr('validation') !== undefined) { fields.push(new Field(field)); } }); this.fields = fields; } Form.prototype = { validate : function() { for(field in this.fields) { this.fields[field].validate(); } }, isValid : function() { for(field in this.fields) { if(!this.fields[field].valid) { this.fields[field].field.focus(); return false; } } return true; } } /* Field factory */ var Field = function(field) { this.field = field; this.valid = false; this.attach("change"); } Field.prototype = { attach : function(event) { var obj = this; if(event == "change") { obj.field.bind("change",function() { return obj.validate(); }); } if(event == "keyup") { obj.field.bind("keyup",function(e) { return obj.validate(); }); } }, validate : function() { var obj = this, field = obj.field, errorClass = "errorlist", errorlist = $(document.createElement("ul")).addClass(errorClass), types = field.attr("validation").split(" "), container = field.parent(), errors = []; field.next(".errorlist").remove(); for (var type in types) { var rule = $.Validation.getRule(types[type]); if(!rule.check(field.val())) { container.addClass("error"); errors.push(rule.msg); } } if(errors.length) { obj.field.unbind("keyup") obj.attach("keyup"); field.after(errorlist.empty()); for(error in errors) { errorlist.append("<li>"+ errors[error] +"</li>"); } obj.valid = false; } else { errorlist.remove(); container.removeClass("error"); obj.valid = true; } } } /* Validation extends jQuery prototype */ $.extend($.fn, { validation : function() { var validator = new Form($(this)); $.data($(this)[0], 'validator', validator); $(this).bind("submit", function(e) { validator.validate(); if(!validator.isValid()) { e.preventDefault(); } }); }, validate : function() { var validator = $.data($(this)[0], 'validator'); validator.validate(); return validator.isValid(); } }); $.Validation = new Validation(); })(jQuery); I am allowing my customers to use a rich text editor (wysiwyg) on a jsp page to create snippets of HTML code that can be used to describe their items. When they want to add an image, table or custom tag (something we wrote), they are presented with a properties box created using javascript on the same page just below the editor. Upon clicking 'Insert' button on the properties box, I use javascript to create an HTML string with the tag information and insert the string into the edited page where the cursor was. The problem is that I can't seem to find a reliable way to know where the cursor was. More information: I am a C programmer who morphed to a Java programmer who knows some javascript. The JSP page looks like this: -------------------------------------------------------------------- Some text and text fields for some basic information -------------------------------------------------------------------- The javascript wysiwyg editor -------------------------------------------------------------------- The properties box (changes depending on the type of item being inserted) -------------------------------------------------------------------- Submit button, etc. for the page (so the information can be persisted) I have tried: 1. Seven days of searching the web for helpful hints. 2. Using a popup window to get the properties (doesn't work because in IE7, closing the popup also kills the session... I need to use some of the beans on the main window on the popup.) 3. Processing onMouseDown and onKeyDown events storing the element information in a global variable so I could use it later to know the point of insertion. (Has not been reliable and the arrow keys present real problems with where the cursor ends up as that is different from where it was pressed.) I am frustrated because I don't seem to be gaining on the problem. I suspect it is because I have missed something very simple. Does anyone have any ideas? Thanks in advance. Carl greetings everyone! this is my first time trying to join this javascript community. Well then, now I'm telling about my miss-understanding of this keywords of javascript here... here's the html Code: <fieldset > <legend>Attachment</legend> <table id="attachment" style="height: 50px;" width="200" border="0"> <th width="19%">Title</th> <th width="26%">File</th> <th width="41%">Description</th> <th width="6%">Upload</th> <th width="6%">More File</th> <tr> <td><input name="title" type="text" value="- none -" size="33" maxlength="50"></td> <td><input name="filepath" type="file" size="33"></td> <td><input name="description" type="text" value="- none -" size="60" maxlength="200"></td> <td><input name="upload" type="button" value=" Upload " onclick="upload(this)"> </td> <td><div align="center"> <input onclick="addMoreFile()" type="button" value="+"> </div></td> </tr> </table> <!-- end Attachment --> </fieldset> the aim is that the upload button would eventually changed into image and then changed back to a link. That one is already done here's the javascript Code: var attRow; function upload(obj){ // obtain the table pointer var attTable = document.getElementById('attachment'); // post file into the jsp file // changing the image // get parent pointer of this element var par = obj.parentNode; var loImage = document.createElement('img'); loImage.setAttribute('src', 'images/loading1.gif'); par.innerHTML = ''; par.appendChild(loImage); // create the removal link var text = document.createTextNode('remove'); var liRem = document.createElement('a'); liRem.setAttribute('href','javascript:removeFile(this)'); liRem.appendChild(text); par.innerHTML = ''; par.appendChild(liRem); } function removeFile(obj){ // post fileid // change the image } function addMoreFile(){ // create fully file upload row // consist of two text elements, file element, and 1 button. var nFileTitle = document.createElement('input'); nFileTitle.setAttribute('name','title'); nFileTitle.setAttribute('type','text'); nFileTitle.setAttribute('size', '33'); nFileTitle.setAttribute('value','- none -'); nFileTitle.setAttribute('maxlength','50'); var nFilePath = document.createElement('input'); nFilePath.setAttribute('name', 'filepath'); nFilePath.setAttribute('type', 'file'); nFilePath.setAttribute('size', '33'); var nDesc = document.createElement('input'); nDesc.setAttribute('name', 'description'); nDesc.setAttribute('type', 'text'); nDesc.setAttribute('value','- none -'); nDesc.setAttribute('size', '60'); nDesc.setAttribute('maxlength', '200'); var nUpButton = document.createElement('input'); nUpButton.setAttribute('name', 'upload'); nUpButton.setAttribute('type', 'button'); nUpButton.setAttribute('value', ' Upload '); nUpButton.setAttribute('onclick', 'upload(this)'); // empty element var ksg = document.createTextNode(' '); // obtain the table pointer var attTable = document.getElementById('attachment'); attRow = attTable.rows.length; alert(attRow); var nextRow = attTable.insertRow(attRow); var ceL = nextRow.insertCell(0); ceL.appendChild(nFileTitle); ceL = nextRow.insertCell(1); ceL.appendChild(nFilePath); ceL = nextRow.insertCell(2); ceL.appendChild(nDesc); ceL = nextRow.insertCell(3); ceL.appendChild(nUpButton); ceL = nextRow.insertCell(4); ceL.appendChild(ksg); } the problem arise when I try to use the removeFile() function using this keywords. into these; Code: function removeFile(obj){ // post fileid // change the image back // get parent pointer of this element var par = obj.parentNode; var loImage = document.createElement('img'); loImage.setAttribute('src', 'images/loading1.gif'); } I try to apply the same approach as the upload() function. But instead the this object which is pointing at the parent node seems unreliable. Is there any missing point i haven't observed? I found a simple script from the net that redirects the user to another page after timeout. I want to redirect the user to an anchor (an anchor called #done) in the SAME page, but i couldn't do it. Here's the code. Any help will be appreciated. Thank you. Code: <form name="redirect"> <center> <font face="Arial"><b>You will be redirected to the script in<br><br> <form> <input type="text" size="3" name="redirect2"> </form> seconds</b></font> </center> <script> <!-- /* */ //change below target URL to your own var targetURL="http://myurl.com" // tried #done/samepage.htm as also samepage.htm/#done //change the second to start counting down from var countdownfrom=6 var currentsecond=document.redirect.redirect2.value=countdownfrom+1 function countredirect(){ if (currentsecond!=1){ currentsecond-=1 document.redirect.redirect2.value=currentsecond } else{ window.location=targetURL return } setTimeout("countredirect()",1000) } countredirect() //--> </script> This code: when you click a link it jumps to an anchor point on the page and scrolls there smoothly. I was wondering how I get the same effect if I want the link to jump to another page? A normal anchor point on another page would set the href to, for instance, 'index.html#contact' but it won't work in this case as the javascript isn't reading the '#'. Any ideas?? Code: <script type="text/javascript" src="jquery.js"></script> <script> function goToByScroll(id){ $('html,body').animate({scrollTop: $("#"+id).offset().top},'slow'); } </script> </head> <body> <ul> <li><a href="javascript:void(0)" onClick="goToByScroll('contact')">Go to anchor 1</a></li> </ul> Please could anyone offer any advice, in simple terms on how to add anchor points to a page in order to create a smooth scroll element such as this one: http://www.kryogenix.org/code/browser/smoothscroll/#top Any help would be much appreciated. |