JavaScript - Limiting Drop Zone To One Image
Hi I am wondering how I would limit the drop zones to just one image per drop zone?
Code: <ul id="images"> <li><a id="1" draggable="true"><img src="images/1.jpg" value = "flower"></a></li> <li><a id="2" draggable="true"><img src="images/2.jpg" value = "boy"></a></li> <li><a id="3" draggable="true"><img src="images/3.jpg" value = "girl"></a></li> </ul> <form name = "objects" id="form" action = "form.php" method = "post"> <div class="drop_zones"> <div class="drop_zone" id="drop_zone1" droppable="true" type = "text" name = "drop_zone1"> </div> <div class="drop_zone" id="drop_zone2" droppable="true" type = "text" name = "drop_zone2"> </div> <div class="drop_zone" id="drop_zone3" droppable="true" type = "text" type = "file" name = "drop_zone3"> </div> </div> Code: var addEvent = (function () { if (document.addEventListener) { return function (el, type, fn) { if (el && el.nodeName || el === window) { el.addEventListener(type, fn, false); } else if (el && el.length) { for (var i = 0; i < el.length; i++) { addEvent(el[i], type, fn); } } }; } else { return function (el, type, fn) { if (el && el.nodeName || el === window) { el.attachEvent('on' + type, function () { return fn.call(el, window.event); }); } else if (el && el.length) { for (var i = 0; i < el.length; i++) { addEvent(el[i], type, fn); } } }; } })(); var dragItems; updateDataTransfer(); var dropAreas = document.querySelectorAll('[droppable=true]'); function cancel(e) { if (e.preventDefault) { e.preventDefault(); } return false; } function updateDataTransfer() { dragItems = document.querySelectorAll('[draggable=true]'); for (var i = 0; i < dragItems.length; i++) { addEvent(dragItems[i], 'dragstart', function (event) { event.dataTransfer.setData('obj_id', this.id); return false; }); } } addEvent(dropAreas, 'dragover', function (event) { if (event.preventDefault) event.preventDefault(); this.style.borderColor = "#000"; return false; }); addEvent(dropAreas, 'dragleave', function (event) { if (event.preventDefault) event.preventDefault(); this.style.borderColor = "#ccc"; return false; }); addEvent(dropAreas, 'dragenter', cancel); // drop event handler addEvent(dropAreas, 'drop', function (event) { if (event.preventDefault) event.preventDefault(); // get dropped object var iObj = event.dataTransfer.getData('obj_id'); var oldObj = document.getElementById(iObj); // get its image src var oldSrc = oldObj.childNodes[0].src; oldObj.className += 'hidden'; var oldThis = this; setTimeout(function() { oldObj.parentNode.removeChild(oldObj); // remove object from DOM // add similar object in another place oldThis.innerHTML += '<a id="'+iObj+'" draggable="true"><img src="'+oldSrc+'" /> </a>'; // and update event handlers updateDataTransfer(); // little customization oldThis.style.borderColor = "#ccc"; }, 500); return false; }); Anyone know? Similar TutorialsCan someone help me modify this script be set to a specific Time Zone rather than picking up the time from the local machine? I want it to countdown to 6:00 am EST. http://javascript.internet.com/time-...countdown.html Can anyone tell me what to add where if it is possible? Thank you in advance. Hi Script Experts I am facing issue in below code for Brisilia time zone.(GMT-3). Issue comes in October month only. It is going tobig loop. I am not getting how Date object is behaving here. Thanks in advance Pranav Sharma *********************************** <script type="text/javascript"> var nDate; var nCurrentYear = 2011; var nCurrentMonth = 10; nYear=2011; nMonth=10; var date = new Date(nYear, nMonth-1, 1); document.write('Month:'+date.getMonth() +':CurrentMonth:'+nCurrentMonth); while (date.getMonth() == nCurrentMonth-1) { nDate = date.getDate(); document.write(date.toDateString()); date = new Date(nCurrentYear, date.getMonth(), date.getDate()+1); } </script> ********************************** what is the best way to count the seconds between each onkeyup to "autosave" without sending an ajax command after each key? id like my script to update after 2 seconds of no typing.... (yes, jquery is in use on the page) Code: function microtime (get_as_float) { var now = new Date().getTime() / 1000; var s = parseInt(now, 10); return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s; } var lastKeyUp=0; function saveChange(id,field,value){ thismicrotime=microtime(true); if(lastKeyUp == 0 || (thismicrotime-lastKeyUp) >= 2000000){ $.get("saveChange.php", { 'field': field, 'value': value, 'id': id }, function(data){ lastKeyUp=thismicrotime; }, 'xml' ); } } Code: <input type="text" name="field1" onkeyup="saveChange('2','field1',this.value);" /> i'd use onchange or onblur but that requires you to unfocus the field before it saves... I have the following javascript code: Code: elms=document.getElementById('friends').getElementsByTagName('li'); for(var fid in elms){ if(typeof elms[fid] === 'object'){ fs.click(elms[fid]);} } Which grabs all "li" tags with the ID "friends" , and then goes through and clicks all of those elements. How would I go about having it to where it only clicks up to 200 elements, and not all of them. I'm programming a function that breaks a massive string (2 million + characters) into "manageable" chunks of 500,000 characters. The function goes as follows: Code: var json_string = "{'action':'message-send','recipients':recipients,'message':message"; var bytes_chunks = scripting.messages.voice.recorder.bytes.chunk(500000); $.each(bytes_chunks,function(i,v){ json_string += ",'voice_bytes_"+i+"':'"+v+"'"; }); json_string += "}"; As you can see, everything should work fine, and the function should return a stringified json array (which would be parsed and sent to a server) but the string is truncated and function exited after the first interval. When I decrease the length of "v" using substr to 5 characters, all the expected children are returned. What could the problem be? If you open two tabs, http://www.google.com/imghp and another one, you are able to drag and drop an image from the other tab to the google search tab, and google will search similar images. i can't figure out how that works, does anybody know how? Hi all, using the Draggable featu http://jqueryui.com/demos/draggable/ How can I limit the draggable div so it hits the sides of the container? It states I can do this: Quote: Constrains dragging to either the horizontal (x) or vertical (y) axis. Possible values: 'x', 'y'. Code examples Initialize a draggable with the axis option specified. $( ".selector" ).draggable({ axis: 'x' }); Get or set the axis option, after init. //getter var axis = $( ".selector" ).draggable( "option", "axis" ); //setter $( ".selector" ).draggable( "option", "axis", 'x' ); But I don't really understand it. :S Not great with Javascript - so please make it simple! Thanks. I would appreciate some help, I want to use the Drop Down Image selector II script on a website, to display fabric, as there is a large number of samples, I want to break the list up alaphabetically. Is is possible to use the script more than once on a page, when I tried to do this the script did not work, if it can not be used more than once on a page, has anyone seen a program that could be. Thanks I'm currently setting up a website that will display, for each link in the drop down, an image below the box, and text or, if necessary, an image to the right, describing the item & listing materials & prices. I've tried iframes with a drop down, but because I'm hosted with BraveHost, I end up with 50 ads on the main page, and 50 more in the iframe, so I'd like to avoid that if possible. If you want to see what I'm looking for, go here. http://andicrafts78.bravehost.com/test.html. How can I modify the drop down selector to make it happen?
i've got a drop down menu and an image fader. i need the drop down menu to overlay on top of the fader. currently it drops down under it. i've tried messing about with z-index but not getting far. any ideas? thanks http://www.thebluebus.co.uk/tempwest/ In my previous post, I asked how to create a function that would allow me to add to or subtract from a maxvalue, and thankfully I got help regarding that. However, something's got me stumped for the past few weeks that I still can't resolve... This is the relevant code: Code: <html> <head> <script type="text/javascript" language="Javascript"> function chgAdv(btn) { var form = btn.form; var newqty = parseInt(btn.value); var maxqty = form.maxqty; var maxadv = form.maxadv; if (eval("btn.checked") == true && parseInt(maxadv.value) + newqty <= 15) { var newmax = parseInt(maxqty.value) - newqty; var newadv = parseInt(maxadv.value) + newqty; } else if (eval("btn.checked") == false && parseInt(maxadv.value) - newqty >= 0) { var newmax = parseInt(maxqty.value) + newqty; var newadv = parseInt(maxadv.value) - newqty; } else { var newmax = parseInt(maxqty.value); var newadv = parseInt(maxadv.value); } if ( newadv >= 0 && newmax >= 0) { maxqty.value = newmax; maxadv.value = newadv; } } function chgDis(btn) { var form = btn.form; var newqty = parseInt(btn.value); var maxqty = form.maxqty; var maxdis = form.maxdis; if (eval("btn.checked") == true && parseInt(maxdis.value) + newqty <= 10) { var newmax = parseInt(maxqty.value) + newqty; var newdis = parseInt(maxdis.value) + newqty; } else if (eval("btn.checked") == false && parseInt(maxdis.value) - newqty >= 0) { var newmax = parseInt(maxqty.value) - newqty; var newdis = parseInt(maxdis.value) - newqty; } else { var newmax = parseInt(maxqty.value); var newdis = parseInt(maxdis.value); } if (newdis >= 0 && newmax >= 0) { maxqty.value = newmax; maxdis.value = newdis; } } </script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <form name="f1"> <b>Advantages</b> (<input type="text" class="RO" name="maxadv" value="0" />)<br /> <input type="checkbox" class="RO" name="Absolute Direction" onclick="chgAdv(this);" value="2" />Absolute Direction<br /> <input type="checkbox" class="RO" name="Allies" onclick="chgAdv(this);" value="3" />Allies<br /> <hr> <b>Disadvantages</b> (<input type="text" class="RO" name="maxdis" value="0" />)<br /> <input type="checkbox" class="RO" name="Antisocial" onclick="chgDis(this);" value="2" />Antisocial<br /> <input type="checkbox" class="RO" name="Ascetic" onclick="chgDis(this);" value="4" />Ascetic<br /> max quantity: <input type="text" readonly class="RO" name="maxqty" value="40" /> </form> </body> </html> styles.css is simply: Code: input.RO { border: none; width: 40px; text-align: center; } As it stands, it works as long as the total value is less than or equal to the limit (for advantages it's 15, for disadvantages it's 10). However, the moment it goes past the limit -- for instance, if you change Antisocial's value from 2 to 7, or if you add several additional checkboxes with any values -- the whole thing starts going crazy; specifically, maxvalue doesn't revert to 40 when the all the checkboxes are unchecked. What I'd want to happen is that the user cannot select or apply advantages or disadvantages if the maximum advantage is greater than 15 or the maximum disadvantages is greater than 10. I'm thinking that a button for adding disadvantage points to/subtracting advantage points from the maxvalue (that becomes disabled if the user goes past his limit on advantages/disadvantages) is useful at this point, but I'm really stumped on the implementation of the idea. An alternate idea of mine is that all other advantage/disadvantage checkboxes would become disabled if their value is greater than the remaining number of points, but I don't know how that is possible either. Any and all help is greatly appreciated. I want to limit the number of characters shown in a select box when its 'dormant' ie. I want the drop down to have the full word but when something is selected, I want it to show only the first 3 characters of the word. I can limit the width to a fixed px width but the right width is different depending on the word. (its a drop down of month names, I want them to have the full 'grown up' name in the drop down but that's too long and cumbersome for the space I have, I've trimmed it down by setting the width in CSS but it looks so much neater when the first 3 characters just show in the box rather than 4 or 3.5) Dear Forum Members HI, I am no coder, however I am modifying my website and changing the slideshow to the one found on this website, most wonderful, the Cut & Paste JavaScript Slideshow( http://www.javascriptkit.com/script/.../jsslide.shtml ) I have it working now, and I have but one question, does the code include a way to limit the number of times that it cycles through the slides? So it just freezes on one photo after x number of cycles? many thanks, and happy holidays... I'm a complete newbie so please excuse me if this is obvious. I'd like to have a drop down menu that pops up a small new window with an image. So for, every attempt results in the image appearing in a new tab instead of a small, pop up style window. Here's my form <select name="parms"> <option value="AirTemp.jpg">AirTemp</option> <option value="Humidity.jpg">Humidity</option> <option value="Windspeed.jpg">Wind Speed</option> </select> Many thanks. I have a drop down menu and an image slider that both use javascript code to function. The image slider appears right below the menu but when the actual menu drops down, the drop down part of the menu goes behind the image slider. How do I make it so that the menu drops above the image slider and not behind it? Hi all, I hope you are able to help me out. I have a a page (see code below, I have compressed it to 2 images) where I want to let the user drag and drop images to anywhere on the page (I have achieved this.) What I want to be able to do is allow the user to dock 2 images together. In the example below the 2 images are horizontal lines. What I want the user to be able to do is move the images together and dock them so that they form one horizontal line. When the user moves one of the pictures both will move and stay docked. my initial idea was that when the user selects "dock" I somehow move both images into a div and make the div dragable, that way both images move together. Then if the user selects "undock" both images are removed from the div and become draggable again. I hope this makes sense. Can anyone help? [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> <title>drag, Drop and dock</title> <style type="text/css"> .drag { border: 1px solid black; background-color: rgb(240, 240, 240); position: relative; padding: 0.5em; margin: 0 0 0.5em 1.5em; cursor: move; } </style> <script language="JavaScript" type="text/javascript"> <!-- // this is simply a shortcut for the eyes and fingers function $(id) { return document.getElementById(id); } var _startX = 0; // mouse starting positions var _startY = 0; var _offsetX = 0; // current element offset var _offsetY = 0; var _dragElement; // needs to be passed from OnMouseDown to OnMouseMove var _oldZIndex = 0; // we temporarily increase the z-index during drag InitDragDrop(); function InitDragDrop() { document.onmousedown = OnMouseDown; document.onmouseup = OnMouseUp; } function OnMouseDown(e) { // IE is retarded and doesn't pass the event object if (e == null) e = window.event; // IE uses srcElement, others use target var target = e.target != null ? e.target : e.srcElement; // for IE, left click == 1 // for Firefox, left click == 0 if ((e.button == 1 && window.event != null || e.button == 0) && target.className == 'drag') { // grab the mouse position _startX = e.clientX; _startY = e.clientY; // grab the clicked element's position _offsetX = ExtractNumber(target.style.left); _offsetY = ExtractNumber(target.style.top); // bring the clicked element to the front while it is being dragged _oldZIndex = target.style.zIndex; target.style.zIndex = 10000; // we need to access the element in OnMouseMove _dragElement = target; // tell our code to start moving the element with the mouse document.onmousemove = OnMouseMove; // cancel out any text selections document.body.focus(); // prevent text selection in IE document.onselectstart = function () { return false; }; // prevent IE from trying to drag an image target.ondragstart = function() { return false; }; // prevent text selection (except IE) return false; } } function ExtractNumber(value) { var n = parseInt(value); return n == null || isNaN(n) ? 0 : n; } function OnMouseMove(e) { if (e == null) var e = window.event; // this is the actual "drag code" _dragElement.style.left = (_offsetX + e.clientX - _startX) + 'px'; _dragElement.style.top = (_offsetY + e.clientY - _startY) + 'px'; } function OnMouseUp(e) { if (_dragElement != null) { _dragElement.style.zIndex = _oldZIndex; // we're done with these events until the next OnMouseDown document.onmousemove = null; document.onselectstart = null; _dragElement.ondragstart = null; // this is how we know we're not dragging _dragElement = null; } } //--> </script> </head> <body> <img class="drag" src="Horizontal_Line.png" alt="A horizontal line" /> <img class="drag" src="Horizontal_Line.png" alt="Another horizontal line" /> </body> </html> [CODE] Hello All, I am trying to find a solution for this ..... kindly help incase you know.... I need a drop down menu to appear when I left-click an image.... have tried a lot but failed... Please help me out on this Thanks in advance,,, Regards I saw this on the web the other day and didn't mark the page I found it on. How do I change an image based on what selection is made in a drop down? Kathy Something similar to the navigation menu on http://www.gamewearteamsports.com/. You hover over a link and a box appears below that spreads the width of the menu itself. Friend of mine told me it was using actionscript but I have no idea how to create a drop down box (not menu). Any ideas? My friend told me Dreamweaver has the ability t create a drop down box but I have no idea. Also does anyone know how to create an image slider similar to the one on that site? A slider that fades from one image to the next with the navigation arrows on the left and right side and the dots on top left? I have added "Swap Image" into a page which already has a Drop Down Menu. However the Drop Down Menu stopped working. I know I have to remove the last line from the Drop Down Script ...window.onload=startList;... and integrate it into the <body tag> but I can't seem to figure it out. Someone please help... Below is the script for the drop down menu. // JavaScript Document startList = function() { if (document.all&&document.getElementById) { navRoot = document.getElementById("nav"); for (i=0; i<navRoot.childNodes.length; i++) { node = navRoot.childNodes[i]; if (node.nodeName=="LI") { node.onmouseover=function() { this.className+=" over"; } node.onmouseout=function() { this.className=this.className.replace(" over", ""); } } } } } window.onload=startList; Here is the page I'm trying to work with. http://sigautoparts.com/home-test.htm |