javascript - Function inside object -


well, don't know if return in transform function can work, but, know if there way can similar this? put function inside object...

var t = $(this).scrolltop(); var h = $(window).height();  function transform(val){     return "-webkit-transform": "translatey(" + val + "%)",     "-ms-transform": "translatey(" + val + "%)",     "transform": "translatey(" + val + "%)"; }  $("#header").css({     opacity: 50 * (t/h),     tranform(50 * (t/h)) }); 

you use css extension language (like less or scss) handle variables, process , use simple stylesheet.

if want stick js, suggest returning hash transform , extending later, like:

function transform(val) {   return {     "-webkit-transform": "translatey(" + val + "%)",     "-ms-transform": "translatey(" + val + "%)",     "transform": "translatey(" + val + "%)"   } }  function transformwithopacity(val) {   var base = transform(val);   base["opacity"] = val;   return base; }  var num = 50 * (t/h); $("#header").css(transformwithopacity(num)); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -