JavaScript - Over-riding I-beam Cursor Onmousedown-drag
I have created a drag script and am having a problem with the cursor. When I hover over the div, the cursor becomes "move" as I want it to be. But if I click, then drag it changes to the I-beam cursor. I am wondering what I can do to get it to stay "move" or whatever I'd like it to be. I know things like onselectstart, etc, but that doesn't seem to do anything. Thanks for your time.
Similar Tutorialsis it possible to reposition the ibeam cursor in a textarea. im using a button to insert stuff into a text area and then focus but i would like the selector to appear at a certain point. Thanks, Steve, When a user pushes their mouse down on a DOM element I want to allow them to move it, so I would like to setup an on mouse move function. The code i have is: Code: var newHeader = document.createElement("div"); newHeader.id = "header" + tabID; newHeader.className = "windowHeader"; newHeader.onmousedown = 'desktop.onmousemove = moveWindow('+tabID+');'; newHeader.onmouseup = 'desktop.onmousemove = null;'; newWindow.appendChild(newHeader); However it doesn't work hence why I'm here... Any help appreciated! on my page: http://www.jbiddulph.com/john-drag.html I want to be able to show the TOP and LEFT position on the textboxes below when I move the box?! Please help?! thanks J I have some code which looks like this. Code: <script type="text/javascript"> function links(){ var links=document.getElementsByTagName("A"); for(var i=0;i<links.length;i++){ links[i].onmousedown=function(i){ return Showalert(links[i]); }; } } function Showalert(link){ alert("link: "+link); } </script> What I want to know is how I can pass the number which 'i' is of the current link being clicked so like this - links hi // i = 0 hello // i = 1 dude // i = 2 so from the for loop I want the i to be passed into the function which "links[i].onmousedown" is outputting so when the user clicks any link on the page the function within the mousedown call can read the number of the link? can anyone help? EDIT: Don't worry I've done it. I have 9 boxes which I can drag around an invisible grid however when the onMouseDown function is called for the first time on each of the boxes, they behave erratically, then once all boxes have been clicked once, the entire script works as it should. I've tried using default values when declaring the variables however it doesn't seem to do anything. Does this happen with anyone else, anything obvious I'm missing. Code: <html> <head> <script language="javascript"> var x; var y; var org_top; var org_left; var diff_org_top; var diff_org_left; var element; var element2; var being_dragged = false; var newleft; var newtop; function mouse_move(event) { if(event.offsetX || event.offsetY) { x=event.offsetX; y=event.offsetY; } else { x=event.pageX; y=event.pageY; } if(being_dragged = true) { document.getElementById(element).style.top = y-diff_org_top +'px'; document.getElementById(element).style.left = x-diff_org_left +'px'; } } function mouse_down(ele_name) { being_dragged = true; element = document.elementFromPoint(x, y).id; org_top = document.getElementById(element).style.top; org_left = document.getElementById(element).style.left; diff_org_top = y-org_top.substring(org_top.length-2,org_top); diff_org_left = x-org_left.substring(org_left.length-2,org_left); } function mouse_up() { being_dragged = false; newtop = Math.floor((y-diff_org_top+100)/200) * 200; newleft = Math.floor((x-diff_org_left+100)/200) * 200; if (newtop<0) { newtop = 0; } else if (newtop>400) { newtop = 400; } if (newleft<0) { newleft = 0; } else if (newleft>400) { newleft = 400; } document.getElementById(element).style.display = 'none'; if (document.elementFromPoint(newleft+100, newtop+100).id != '') { element2 = document.elementFromPoint(newleft+100, newtop+100).id; document.getElementById(element2).style.top = org_top; document.getElementById(element2).style.left = org_left; element2 = null } document.getElementById(element).style.display = 'block'; document.getElementById(element).style.top = newtop +'px'; document.getElementById(element).style.left = newleft +'px'; element = null; } </script> <style type="text/css"> .box { float:left; display:block; width:190; height:190; margin:5; position:absolute; } .red { background:red; top:0; left:0; } .blue { background:blue; top:0; left:201; } .yellow { background:yellow; top:0; left:401; } .green { background:green; top:201; left:0; } .violet { background:violet; top:201; left:201; } .orange { background:orange; top:201; left:401; } .maroon { background:maroon; top:401; left:0; } .lime { background:lime; top:401; left:201; } .indigo { background:indigo; top:401; left:401; } </style> </head> <body onMouseMove="mouse_move(event)"> <div id="one" class="red box" onMouseDown="mouse_down('one')" onMouseUp="mouse_up()"> </div> <div id="two" class="blue box" onMouseDown="mouse_down('two')" onMouseUp="mouse_up()"> </div> <div id="three" class="yellow box" onMouseDown="mouse_down('three')" onMouseUp="mouse_up()"> </div> <div id="four" class="green box" onMouseDown="mouse_down('four')" onMouseUp="mouse_up()"> </div> <div id="five" class="orange box" onMouseDown="mouse_down('five')" onMouseUp="mouse_up()"> </div> <div id="six" class="violet box" onMouseDown="mouse_down('six')" onMouseUp="mouse_up()"> </div> <div id="seven" class="maroon box" onMouseDown="mouse_down('seven')" onMouseUp="mouse_up()"> </div> <div id="eight" class="lime box" onMouseDown="mouse_down('eight')" onMouseUp="mouse_up()"> </div> <div id="nine" class="indigo box" onMouseDown="mouse_down('nine')" onMouseUp="mouse_up()"> </div> </body> </html> Hello, If you will open: joketube.tv (please use admin as username and admin as password) and have a look on the top menu you will find UPLOAD link. Please click on it and you will see 'popup window'. Everything is ok with except that all parts of the window is dragable... I was expecting following. After placing some container DIV element (none transparent) with higher z-index over dragable background DIV. This region (with higher z-index) would become NONE dragable! BUT what I got is that even if DIV is hidden behinde other DIV elements, onmousedown is still working for that hidden DIV. Why this happened and how can I solve this problem? Thank you in advance for any suggestion I have some own cursor with a .cur file. But it's very annoying to try changing each part from the css to the new cursor. Is there no aviable script in JS or HTML or CSS or whatever there is, that i can press the link for all cursor like: Pointer, defaut, wait, stop, link and so on. So they all changes into my own? Without having those white cursor. I would like to create a caret for a textarea like the one he http://www.dynamicdrive.com/forums/s...4576#post74576 it works great if I want a white background but when I changed it to black and tried to change the textarea's text color to yellow: Code: <textarea type="text" id="setter" style="color:yellow;"onkeydown="writeit(this, event);moveIt(this.value.length, event)" onkeyup="writeit(this, event)" onkeypress="writeit(this, event);"></textarea> I don't see anything on the screen other than the blinking cursor I need a javascript that will print out the X and Y of the mouse on the screen as I move the mouse and keep up to date. The X and the Y must also be stored in a variable. (Trying to increase my knowledge of javascript so that I can make my web sites better and my experiments are all in making games) Do you guys have any idea how I could move a div around a page on mouse down? Like drag and drop it where I want it to be on the page and grab its x,y position? If you guys have any code snippets or tips that would be greatly appreciated thanks! i need typing cursor back in first text box after clicking ok of alert [CODE] <html> <head> <script type='text/javascript'> function player() { document.getElementById("Player2").value= document.getElementById("Player1").value; } function notEmpty(elem, helperMsg){ if(elem.value.length == 0){ alert(helperMsg); elem.focus(); return false; } return true; } </script> </head> <body> <form> Player:<input type="Name" id="Player1" onkeyup="player()"/> <input type="Name" id="Player2" DISABLED /> <input type='button' onclick="notEmpty(document.getElementById('Player2'), 'Please fill in player field!')" value='Submit' /> </form> </body> </html> [ICODE] I'm trying to write a function that is similar to the ctrl+f functionality you get in IE, where you have a search string and when you click 'next' the whole string if matched is highlighted by the cursor. This works fine for inputs and text areas using the following code: Code: function setCaretPos(obj, start, end) { var range = obj.createTextRange(); range.moveStart('character', start); range.moveEnd('character', end - obj.value.length); range.select(); } But now I need to get it to work for normal text in a text node that is in the HTML/DOM. Is there an equivalent way of making the above method work for text in text nodes? Alternatively is there a way to make the browser (IE) at least focus on some text in a text node? (I could then highlight it with CSS styles). Hi, Would you please try the following in IE: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script> <style type="text/css"> * { font-family: Verdana; font-size: 96%; } label { width: 10em; float: left; } label.error { float: none; color: red; padding-left: .5em; vertical-align: top; } p { clear: both; } .submit { margin-left: 12em; } em { font-weight: bold; padding-right: 1em; vertical-align: top; } </style> <script> $(document).ready(function(){ $("#curl").focus(function(){ if( this.value == this.defaultValue ) { $(this).val("http://"); } }); $("#commentForm").validate(); }); </script> </head> <body> <form class="cmxform" id="commentForm" method="get" action=""> <fieldset> <legend>A simple comment form with submit validation and default messages</legend> <p> <input id="cname" name="name" size="25" class="required" value="Name" /> </p> <p> <input id="cemail" name="email" size="25" class="required email" value="Email" /> </p> <p> <input id="curl" name="url" size="25" class="url" value="URL" /> </p> <p> <textarea id="ccomment" name="comment" cols="22" class="required">Comment</textarea> </p> <p> <input class="submit" type="submit" value="Submit"/> </p> </fieldset> </form> </body> </html> As you see the cursor goes back to the beginning of the field if you focus on the URL field. It works with no problem in other browsers. How can it be corrected? Thanks for any help! I've got the following html code for a button - how can I get the cursor to turn into the hand shape when the mouse is over the button? Thanks PHP Code: <INPUT NAME="btn_cancel" TYPE="button" VALUE="Cancel" onClick="cancel_button_click()";> Good day! In my javascript code I have a function for the enter key. I want to add cursor key in that function/ I research about the coding for cursor key but I can't find the code same on what I want to happen. Here is the code: Code: <script language="javascript"> function handleEnter(e, nextfield) { var characterCode = (e && e.which)? e.which: e.keyCode; if(characterCode == 13) { document.getElementById(nextfield).focus(); return false; } else { return true; } } </script> <input type='text' name='plt' onkeypress='return handleEnter(event,\"b0\");' /> Thank you I have this image map and I need to change the cursor to finger on mouse over: <map name="Map" > <area shape="rect" coords="0,61,121,140" onClick="scr_valid(1)"> <area shape="rect" coords="175,101,445,204" onClick="scr_valid(0)" > </map> Adding href (<area shape="rect" coords="175,100,445,203" onClick="scr_valid(0)" href="#" >) does not work. Any body could help please? Thank you. hello all member help me quick i am create a one form in 10 texbox. i am copy other web Url link when i am paste in textbox cursor not move automatically to the second textbox. and when paste the second textbox the cursor move the not third textbox. please help me how can move automatically cursor textbox only past. not mixmim leg using. only using paste. send completely code java script and input code quickly thanks Hi, Need to put a cursor in a password form on page load here is what I got that does not work. This will be used on a touch screen Code: <script type = "text/javascript"> var count = 2; function validate() { var pw = document.myform.pword.value; var valid = false; /*Failed attempt to put cursor in myform on page Load */ function setCursor(myform){ return set; } var pwArray = ["1701", "Password2", "Password3", "Password4"]; // the corresponding passwords; for (var i=0; i <pwArray.length; i++) { if (pw == pwArray[i]) { valid = true; break; } } if (valid) { alert ("Login was successful"); window.location = "030.html"; return false; } var t = " tries"; if (count == 1) {t = " try"} if (count >= 1) { alert ("Invalid password. You have " + count + t + " left."); document.myform.pword.value = ""; setTimeout("document.myform.pword.select()", 25); count --; } else { alert ("Still incorrect! You have no more tries left!"); document.myform.pword.value = ""; document.myform.pword.disabled = true; return false; } } </script> Thank you for any help. it is required to locate the typing cursor in field after when click ok on java alert thanks in advance !! Hi All, I'm new to the CF forums and also to JavaScript. Trying to get a pop-up div to be draggable, but it doesn't seem to be working. Can someone help me out? I'd be very grateful! JavaScript I'm using: Code: //used for dragging div function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); } function xy(e,v) { return(v?(agent('msie')?event.clientY+document.body.scrollTop:e.pageY):(agent('msie')?event.clientX+document.body.scrollTop:e.pageX)); } function dragOBJ(d,e) { function drag(e) { if(!stop) { d.style.top=(tX=xy(e,1)+oY-eY+'px'); d.style.left=(tY=xy(e)+oX-eX+'px'); } } var oX=parseInt(d.style.left),oY=parseInt(d.style.top),eX=xy(e),eY=xy(e,1),tX,tY,stop; document.onmousemove=drag; document.onmouseup=function() { stop=1; document.onmousemove=''; document.onmouseup=''; }; } //used for pop-up div function pop(div) { document.getElementById(div).style.display='block'; return false } function hide(div) { document.getElementById(div).style.display='none'; return false } Also, here is the HTML: Code: <a href="#" onclick="return pop('myDiv2')">Pop-up div #2</a> - Hidden div shows upon clicking this link, but it won't drag <div class="bubble" onmousedown="dragOBJ(this,event); return false;"> <div id="myDiv2" class="parentDisable"> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. <p><a href="#" onClick="return hide('myDiv2')">Close [X]</a></p> </div> </div> And the CSS: Code: .parentDisable { position:absolute; margin:120px; padding:20px; width:400px; display:none; z-index:3; background-color:#DEDEDE; border:1px solid #DEDEDE; border-radius:5px; -moz-border-radius:5px; -webkit-border-radius:5px; } .bubble { position:fixed; width:400px; top:150px; left:250px; cursor:move; } |