|
I checked the code - it's the bare minimum I need for the mouse over\out so I don't have a lot to remove - although I removed parts.
http://jsfiddle.net/aK5Cz/3/[^]
What do you mean "I can't see what the logic behind detach/attach the event handler every time". There's no logic behind it - I just remove it. It's a built-in function.
The code sometimes reaches the end of mouseover and doesn't execute the mouseout when the cursor is out.
In case you are right about the thread issue: what are my alternatives?
|
|
|
|
|
ThetaClear wrote: "I can't see what the logic behind detach/attach the event handler every time"
What I see that when you are int the mouseOver you detach it and attach mouseOut, in mouseOut you detach mouseOut and attach mouseOver. Why?! Attach both mouseOver and mouseOut once at the beginning...IMHO that's your main problem. You can see that you miss mouseOut when you move mouse too fast...So the thread can't keep up with you and drops events...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Ok.
I don't know if you had a chance of working with easeljs library but if I want to change the color of a certain shape i.e. my rectangle, I need to draw another rectangle and give it a different color and give it a handler for the mouseOut.
To do that, I need to remove the previous rectangle.
I can't just attach mouseOver and mouseOut once in the beginning because I'm removing and adding shapes all the time when the user hover on them so I have to add handlers to them.
Now, for your second remark:
Quote: You can see that you miss mouseOut when you move mouse too fast...So the thread can't keep up with you and drops events...
If that is the problem (moving too fast). how can I solve it?
|
|
|
|
|
You have not recreate the shape to change its color, otherwise what use the library has?! Use graphics.beginFill and stage.update in the mouseOver too! Here a very nice sample of it - http://www.createjs.com/#!/EaselJS/demos/dragdrop[^]
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
|
Read OP carefully - it's about changing the color of a shape on a HTML canvas! No CSS for that
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Right, well, this seems to work as requested:
var stage = null;
var sh = new createjs.Shape();
$(document).ready(function(){
var canvas = document.getElementsByTagName("canvas")[0];
var context = canvas.getContext("2d");
stage = new createjs.Stage(canvas);
// main stage surface
stage.enableMouseOver();
drawInitialShape();
});
function drawInitialShape(){
var cont = new createjs.Container();
stage.addChild(cont);
sh.graphics.beginFill('#FF0000').drawRoundRect(0, 0, 20, 20, 1.5);
sh.x = 150;
sh.y = 150;
cont.addChild(sh);
stage.addChild(cont);
sh.addEventListener('mouseover', function(e){
onSeatMouseOver(e);
});
sh.addEventListener('mouseout', function (e) {
onSeatMouseOut(e);
});
stage.update();
}
var onSeatMouseOver = function (e) {
$('body').css('cursor', 'pointer');
sh.graphics.beginFill('#dddddd').drawRoundRect(0, 0, 20, 20, 1.5);
stage.update();
}
var onSeatMouseOut = function (e) {
$('body').css('cursor', 'auto');
sh.graphics.beginFill('#FF0000').drawRoundRect(0, 0, 20, 20, 1.5);
stage.update();
}
modified 20-Oct-19 21:02pm.
|
|
|
|
|
Exactly!
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Great, it works!!!
Thanks guys!
|
|
|
|
|
I just sat there for exactly a minute going over the square. every time the over and out events triggered every time, may just be your CPU or something similiar
|
|
|
|
|
I have a code that works, but I need to find another way of writing the JS. The code has 1 image, but 4 mp3 for sounds. There are different dots on the image that when you click on the dots should be a different sound.
html part:
<html>
<head>
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<title>OdysseyWare</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="" ie="8">
<link href="/globmedia/ow/css/main_2012_12_12.css" rel="stylesheet">
<link href="/globmedia/ow/css/curric_2012_12_12.css" rel="stylesheet" type="text/css" media="screen">
<link href="/globmedia/lib/jquery-ui/css/jquery-ui-1.8.4.custom.css" rel="stylesheet" type="text/css">
<link href="/globmedia/lib/jquery/css/magnific-popup.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/globmedia/lib/jquery/js/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript" src="/globmedia/lib/jquery-ui/js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>
<script type="text/javascript" src="/globmedia/lib/requirejs/js/require.js" type="text/javascript"></script>
</head>
<body id="body">
<div id="section_0" style="margin: 0px auto; width: 970px">
<div class="presentation">
<presentation>
<div class="section">
<h3>Test 1 New</h3></div>
<p>However, the introduction and conclusion to "The Way to Wealth" show that the author’s
advice is presented in a somewhat ironic way. While the crowd that has gathered to listen to
Father Abraham agrees with him until the "vendue," or sale, begins, they forget the old man’s
and begin to "buy extravagantly."</p>
<p style="TEXT-ALIGN: center">
<div id="test1" data-asset-basepath="media/html5" data-data-basepath="media/html5" data-media-basepath="/globmedia" data-am-controller="media/html5/test1/js/test1.js" style="border: 1px solid black; margin-right: auto; margin-left: auto;"></div>
</p>
</div>
</presentation>
</div>
</div>
<script type="text/javascript">
require.config({
baseUrl:'/globmedia'
});
</script>
<script type="text/javascript" src="/globmedia/html5/animationmanager/js/animationmanager.js"></script>
</body>
</html>
js part
(function(doc){
'use strict';
return function init(){
var _this = this;
require(['createjs','SimpleInteractiveAnimationModule', 'jquery'],function(c, _anm, jq){
var queue = [{id:_this.id + 'audio1',src: _this.assetBasePath + '/test1/media/roles-1_olderMen.mp3', type:'audio'},
{id:_this.id + 'audio2',src: _this.assetBasePath + '/test1/media/roles-1_youngMen.mp3', type:'audio'},
{id:_this.id + 'audio3',src: _this.assetBasePath + '/test1/media/roles-2_olderWomen.mp3', type:'audio'},
{id:_this.id + 'audio4',src: _this.assetBasePath + '/test1/media/roles-2_youngWomen.mp3', type:'audio'},
{id:_this.id + 'image1',src: _this.assetBasePath + '/test1/media/roles.png', type:'image'}];
var pointsNum = 4,
pointsArray = [],
pointColor = '#0040ff';
var pointsObject = {
point1:{
x:382,
y:102},
point2:{
x:146,
y:172},
point3:{
x:455,
y:102},
point4:{
x:312,
y:245},
};
var anm = _anm.getNewInstance();
anm.createSimpleInteraction({parentContainer:_this.element,
queue:queue,
copyright:'2009',
callback:setupClickPoints});
function setupClickPoints(){
for(var i = 0; i < pointsNum; i++)
{
var tempNum = i + 1;
var clickPointShape = new c.Shape();
clickPointShape.graphics.beginFill(pointColor).drawCircle(0,0,16).endFill();
var clickPoint = anm.createSimpleButton(clickPointShape, getClickPoint(i));
anm.updateContainer(clickPoint,{x:pointsObject['point' + tempNum].x,
y:pointsObject['point' + tempNum].y,
alpha:0.01});
pointsArray.push(clickPoint);
}
}
function getClickPoint(audioIndex){
return function(event){
anm.playAudio(audioIndex);
};
}
});
};
}(document));
I just need a different JS code.
Thank you
|
|
|
|
|
|
I using devextreme to develop mobile apps to call my web method wrote in c#. It is success call the web method but the data return is all html source code. I has enable the cross origin in the IIS for the web service.
Below is the jquery get i use to call the web method.
$.get('http://192.168.2.104:81/TwinCatWebServices.aspx/writetempo2', {
btempo2: "'" + viewModel.btempo + "'" }).done(function (result) {
//result is your data
alert("success");
console.log(result);
})
.error(function (result) {
alert(result);
console.log(result);
})
my web method as below
[WebMethod]
public static string writetempo2(string btempo2)
{
string test = "ABC";
return test;
}
I try this as well but also the same
[WebMethod]
public static string writetempo2(string btempo2)
{
string test = "ABC";
var oseries = new System.Web.Script.Serialization.JavaScriptSerializer();
return oseries.Serialize(test);
}
In the browser console, i saw the return result as below:
<title>
AAAAAA
What the mistake I make. Please help.
|
|
|
|
|
Greetings Experts,
I have the following javascript:
<script type="text/javascript">
$(document).ready(function () {
$(
buttonImage:
buttonImageOnly: true, onSelect: function (dateText, inst) {
//Calculate the days here
var days = ($("#txtToDate").datepicker(
//Assign it to textbox
$(
},
onClose: function () { $(this).focus(); }
});
$(
buttonImage:
buttonImageOnly: true, onSelect:
function (dateText, inst) {
$(
}
,
onClose: function () { $(this).focus(); }
});
});
</script>
<script type='text/javascript'>//<![CDATA[
$(window).load(function () {
//Attach click event to button
$(
//Get Values from dropdownlist
var sHour = $(
eHour = $(
//create date format from dropdownlist selected values
var timeStart = new Date(txtFromDate + sHour).getHours();
var timeEnd = new Date(txtToDate + eHour).getHours();
//Calulate the time difference
var hourDiff = timeEnd - timeStart;
//Check if hour difference is less than or equal to 2 hours and show the message accordingly
if (hourDiff <= 2) {
alert("A mininum of 2 hours per reservation is required!");
}
});
});//]]>
</script>
<asp:TextBox ID="txtFromDate" class="fptextbox12" placeholder="MM/DD/YYYY" runat="server" style="width:160px;"></asp:TextBox>
<asp:TextBox ID="txtToDate" class="fptextbox12" placeholder="MM/DD/YYYY" runat="server" style="width:160px;"></asp:TextBox>
The top part of Javascript is used for our datepicker functionality.
A user selects a startdate and an enddate and the total number of days between the startdate and enddate are stored in a control ID called numOfDays.
This works fine.
The second part of the javascript is where I am having issues.
A user selects start time and end time.
If the difference between starttime and endtime is not up to atleast 2 hours, the user is notified that a minimum of two hours is required.
The issue is that I am trying to store the value of startDate and endDate in the two lines below and append time to them but this not working:
var timeStart = new Date(txtFromDate + sHour).getHours();
var timeEnd = new Date(txtToDate + eHour).getHours();
Any ideas what I am doing wrong?
|
|
|
|
|
Hi, samflex, you check if the values
var timeStart = new Date(txtFromDate + sHour).getHours();
var timeEnd = new Date(txtToDate + eHour).getHours();
have the correct value?? Futhermore you need be carefully with the behavior of dropdownlist
Regarts
|
|
|
|
|
Hi Pablo,
Thanks for the prompt response.
What you just posted is what I have though. What am I missing?
Just to explain further, when you select a date value from the datepicker, say for instance, the FromDate, it goes into the control below:
<asp:TextBox ID="txtToDate" class="fptextbox12" placeholder="MM/DD/YYYY" runat="server" style="width:160px;"></asp:TextBox>
What I am trying to do is grab that value and stick it into this:
var timeStart = new Date(txtFromDate + sHour).getHours()
This way, if I select start time of 12:00PM, it should show something like:
06/24/2014 12:00PM.
Same goes with txtToDate. Am I not doing it correctly?
|
|
|
|
|
Hi Samflex, probably you need to use other method to obtain the correct time. JS have a little tricks with the dates and it is a little confused.
Is better than you check this page
http://www.w3schools.com/js/js_dates.asp[^]
that have a lot of information about that.
With the few details that I can see, me mainly suppose that your problem is the format. So please check the page for more information
Regarts.
PD: If need more help, feel free to ask.
|
|
|
|
|
|
In GridView, one column is of checkboxes, I need that if any duplicate record is there for e.g. Name is duplicate and we check its checkbox then record of its duplicate name should also get checked.
|
|
|
|
|
Hi,
Lets assume that you want to do on Name so if check one checkbox with Name Ravi and there are 3 record with Name Ravi then all 3 checkbox should get checked,
so you can do like below, lets say that you are having checkboxes
<div id="mainGridDiv">
<input type="checkbox" value="<Name>"/>
<input type="checkbox" value="<Name>"/>
<input type="checkbox" value="<Name>"/>
</div>
JQuery Code
$("#mainGridDiv input[type=checkbox]").change(function(){
var currValue = $(this).val();
$("#mainGridDiv input[type=checkbox]").find("[value='"+currValue+"']").attr("checked",$(this).checked)
});
NOTE:Assuming checkbox is one column of your grid.
Thanks
Raviranjan
|
|
|
|
|
Hello,
I am using regex to validate some patterns in javascript
My pattern is
[VF][0-9]
And required output is V1-V9 , F1-F9 in any order (eg:V1,V3,V2,F1,F5,F3) OR (eg: F1,F5,F3,V1,V3,V2)
But it is not working can any one help me?
Thanks and regards.
|
|
|
|
|
You question is not clear. The regex provided will check if the string has an V or F (case sensitive) at the first position and then a digit (0-9).
But the part of the 'required output' is confusing! What the input, what the output, what have you expected?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Hello,
My input is something like V1V2-V3-S-V4-F1
And I need to validate the given value contain any of V1 to V9 or F1 to F9 and S.
eg: if user input V20V30-V12-S10-V20-F10 I have to show a error because only 1-9 is allowed.
eg2: if user input R1R2-R3-S-R5-T6 I have to show a error because only V,S,F allowed
And it is not mandatory to enter V/F but S is mandatory.
I think it is clear now.
|
|
|
|
|
|
You need the pattern "[VF][1-9]-?$"
Because V20 matchs [VF][1-9] as V2
Hope this will help you.
|
|
|
|
|