简体   繁体   English

半页背景/列背景

[英]Half page background / Column background

I'm running this JavaScript and CSS ( jsfiddle ) on this website ( animevid-other ) so what I need is to adapt the JavaScript and CSS to the column_sx or have the background centered on the left (where there's the column), is this possible? 我正在此网站( animevid-other )上运行此JavaScript和CSS( jsfiddle ),所以我需要使JavaScript和CSS适应column_sx或将背景居中于左侧(在该列所在的位置),是这个吗可能?

I've found something that could have helped but I think it's not exactly what I need ( multiple-backgrounds-left-half-and-right-half ). 我发现了一些可能有用的方法,但是我认为这并不是我真正需要的( 多背景左半和右半 )。 So since I have not so much knowledge of JavaScript and just a few things about CSS, could you help me? 因此,由于我对JavaScript的了解并不多,而对CSS的了解却很少,您能帮我吗?

Edit : more details here http://i.imgur.com/DsF4q3M.png 编辑:更多详细信息,请参见http://i.imgur.com/DsF4q3M.png

You should set the background to colonna_sx instead of body. 您应该将背景设置为Colonna_sx而不是body。 So add this to colonna_sx. 因此,将其添加到Colonna_sx。

background-repeat: no-repeat;
background-position: center;
background-size: cover;

Then you should change the script. 然后,您应该更改脚本。 If you add jQuery you can change this. 如果添加jQuery,则可以更改它。

 document.body.background ='http://adventureofucm.com/OtherSites/image_background/'+num+'.jpg';

to this. 为此。

var backgroundpic = 'http://adventureofucm.com/OtherSites/image_background/'+num+'.jpg';
$('.colonna_sx').css("background", "url(backgroundpic)");

Without jQuery. 没有jQuery。

document.querySelector('div.colonna_sx').style.backgroundImage = 'url(http://adventureofucm.com/OtherSites/image_background/' + num + '.jpg)';

This should work in most browsers (IE8 and up) http://caniuse.com/#feat=queryselector . 这在大多数浏览器(IE8及更高版本) http://caniuse.com/#feat=queryselector中都可以使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM