jQuery/Javascript basic object property -


im attempting create property called startposition , assign top property button's top value in css.

here jquery:

var morphobject = {      button: $('button.morphbutton'),     container: $('div.morphcontainer'),     overlay: $('div.overlay'),     content: $('h1.content, p.content'),      startposition: {         top: morphobject.button.css('top')         // top: 150,         // left: '20%',         // width: 200,         // height: 70,         // marginleft: -100     }, 

of course, there more, error occurs. error is:

[error] typeerror: undefined not object (evaluating 'morphobject.button') 

how can this? thanks.

morphobject not exist yet when call morphobject.button.

you move outside:

var morphobject = {     button: $('button.morphbutton'),     container: $('div.morphcontainer'),     overlay: $('div.overlay'),     content: $('h1.content, p.content'),      startposition: { } };  morphobject.startposition.top = morphobject.button.css('top'); 

or refer directly jquery element:

var morphobject = {     button: $('button.morphbutton'),     container: $('div.morphcontainer'),     overlay: $('div.overlay'),     content: $('h1.content, p.content'),      startposition: {         top: $('button.morphbutton').css('top')     } }; 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -