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
Post a Comment