admin管理员组文章数量:1363461
Im getting the X and Y co-ordinates or a selected area, Im then using that to set the position of an image in another DIV.
Vars:
selection.x1 (This will need to be a negative value)
selection.y2
I need to write using Javascript or jQuery the following:
div.css('background-position', -selection.xl selection.y2);
But this just give me an error, how can I add two background postion values to the CSS?
Im getting the X and Y co-ordinates or a selected area, Im then using that to set the position of an image in another DIV.
Vars:
selection.x1 (This will need to be a negative value)
selection.y2
I need to write using Javascript or jQuery the following:
div.css('background-position', -selection.xl selection.y2);
But this just give me an error, how can I add two background postion values to the CSS?
Share Improve this question asked Feb 3, 2011 at 9:01 CLiownCLiown 13.9k50 gold badges127 silver badges205 bronze badges1 Answer
Reset to default 10var x1 = '-100';
var y2 = '100';
$('#divID').css({
'background-position':x1+'px '+y2+'px'
});
That works for me, just ensure you have a background-position
in your css as well (even if it's set to 0px 0px
Edit for @logic-unit
$('#divID').css('background-position', x1+'px '+y2+'px');
本文标签: javascriptjQuerySetting background position from variablesStack Overflow
版权声明:本文标题:javascript - jQuery - Setting background position from variables - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743808274a2542582.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论