#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    Puerto Rico
    Posts
    208
    Rep Power
    13

    javascript drawing, script to mozilla


    A friend of mine make this script: http://home.attbi.com/~fredv4/paint/
    is prety cool, but i use most of the time mozilla, and i want to translate it and this is what i have right now:
    Code:
    <script>
    function draw(e){
    if(e.target.tagName != "INPUT"){
    document.getElementById("workarea").innerHTML += "<div style=\"position:absolute; left:"+e.pageX+"px; top:"+e.pageY+"px;\">.</div>";
    }
    
    function downDraw(e){
    if(e.which==1){
    draw;
    }//if
    
    			
    }//func
    	
    function cancelAll(e){
    
    		e.cancelBubble = true;
    		e.returnValue = false;
    		return false;
    }//func
    
    }//func draw
    
    
    
    <!-- Mouse Movement -->
    document.onmousedown = draw; 
    document.onmouseup = cancelAll;
    document.onmousemove = downDraw;
    </script>
    
    <body bgcolor="#CCCCCC" leftmargin="0" topmargin="0" 
    
    rightmargin="0" bottommargin="0" marginwidth="0" 
    
    marginheight="0">
    <div id="workarea" style="BACKGROUND: #FFFFFF; WIDTH: 
    
    100%; HEIGHT: 95%"> </div>
    </body>
    it only draws on one click, it dosent do like the other script that when the click is down, and moving will draw

    any help will be awsome
    thanks in advanced
    +ckill3r
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2003
    Posts
    1,014
    Rep Power
    14
    As far as I know, you can't use
    if(e.which==1){
    to check whether the mouse IS down or not during a mousemove (only used when the state changes).
    (Besides, the value 1 only works in Netscape 6.0. It was corrected into 0 for later versions.)

    How about:
    Code:
    <script type="text/javascript">
    var leftmouseisdown = false
    function down(e) {
    	leftmouseisdown = true
    }
    function draw(e){
    	if (leftmouseisdown) {
    		document.getElementById("workarea").innerHTML += "<div style=\"position:absolute; left:"+e.pageX+"px; top:"+e.pageY+"px;\">.</div>"
    	}
    }
    function up(e) {
    	leftmouseisdown = false
    }
    <!-- Mouse Movement -->
    document.onmousedown = down; 
    document.onmouseup   = up;
    document.onmousemove = draw;
    </script>
    Hope this helps,
    Jeroen
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    Puerto Rico
    Posts
    208
    Rep Power
    13
    dude thanks a lot it worked slow, but work

IMN logo majestic logo threadwatch logo seochat tools logo