I would like to put a jQuery function which contain php in my main.js page. How can I do ?
<script type="text/javascript">
var r = parseInt('<?php the_field('red'); ?>');
var g = parseInt('<?php the_field('green'); ?>');
var b = parseInt('<?php the_field('blue'); ?>');
$("body").css('background-color', 'rgb(' + r + ',' + g + ',' + b + ')');
var alpha = Math.min($(this).scrollTop() / 2000, 1);
var r = Math.round((230-parseInt('<?php the_field('red'); ?>')) * alpha + parseInt('<?php the_field('red'); ?>'));
/* red : (fin - début + début) */
var g = Math.round((230-parseInt('<?php the_field('green'); ?>')) * alpha + parseInt('<?php the_field('green'); ?>'));
/* red : (fin - début + début) */
var b = Math.round((230-parseInt('<?php the_field('blue'); ?>')) * alpha + parseInt('<?php the_field('blue'); ?>'));
$(document).scroll(function() {
/* red : (fin - début + début) */
$("body").css('background-color', 'rgb(' + r + ',' + g + ',' + b + ')');
});
</script>
core js file.(main.js).<script>element implies that this isn't actually a JavaScript file, but is an HTML file. Regardless, you can put PHP code in anything that has a.phpextension and/or is processed by the PHP engine server-side. What have you tried and in what way is it not working?