我想在jQuery上獲取一些包含PHP的CSS。 基本上,我需要這個CSS:在JQuery上注入一些包含PHP的CSS
background: #3c653c url(<?php echo $cta_background_image_url; ?>) no-repeat fixed;
適用於:
wp.customize('cta_background_image', function(value) {
var styles = {
backgroundPosition : "center top",
backgroundBlendMode: "hard-light",
position: "relative",
height: "440px",
backgroundRepeat: "no-repeat",
backgroundAttachment: "fixed",
backgroundSize: "cover",
lineHeight: "200%",
color: "#fff",
overflow: "hidden",
paddingTop: "0",
marginBottom: "0"
};
value.bind(function(to) {
$('.cta-parallax-section ').css('background', 'url(' + to + ')');
$('.cta-parallax-section ').css(styles);
});
});
我需要太多注入,它說的CSS代碼( '背景', 'URL(' +至+ ')') ;
此代碼將應用於WordPress定製器,使其能夠在預覽窗口中實時呈現用戶所做的更改。
我該如何做到這一點?我無法在網上找到有關這種機動的信息。
在此先感謝!
謝謝你的迴應。也許我沒有解釋自己夠好。我真正需要的是:背景:#3c653c url(<?php echo $ cta_background_image_url;?>)no-repeat fixed;在這裏注入:$('.cta-parallax-section').css('background',//代碼在這裏);但我忽略了正確的語法。每次嘗試一些不同的選項時,我都會遇到錯誤。你介意分享你如何去做?再次感謝。 – Ulises
是[this](https://jsfiddle.net/6uv3zgm7/)你在找什麼? – TheOnlyError