<div id="timelapse_speed_control">
<?php
$speed_var;
$timeout_var;
if ($this->uri->segment(4) == 1)
{
$speed_var = 200;
$timeout_var = 200;
}
else if ($this->uri->segment(4) == 2)
{
$speed_var = 200;
$timeout_var = 150;
}
else
{
$speed_var = 200;
$timeout_var = 75;
}
?>
<script type="text/javascript">
$(document).ready(
function(){
speed_var = <?php json_encode($speed_var); ?>;
timeout_var = <?php json_encode($timeout_var); ?>;
$('ul.<?php echo $uri_segment; ?>').innerfade({
speed: speed_var,
timeout: timeout_var,
type: 'sequence',
containerheight: '500px'
});
});
</script>
</div>
The above code is basically asking what the 4th segment in the uri is and then checks it, and changes the speed and timeout of the 'timelapse' accordingly. But it isn't working. It breaks down when testing.
Any idea as to the bug in this? Maybe I'm doing it wrong?
Browser output:
$(document).ready(
function(){
speed_var = ;
timeout_var = ;
$('ul.jeromiedevera').innerfade({
speed: speed_var,
timeout: timeout_var,
type: 'sequence',
containerheight: '500px'
});
});
To fix it add echo
before json_encode
:
<script type="text/javascript">
$(document).ready(
function(){
speed_var = <?php echo json_encode($speed_var); ?>;
timeout_var = <?php echo json_encode($timeout_var); ?>;
$('ul.<?php echo $uri_segment; ?>').innerfade({
speed: speed_var,
timeout: timeout_var,
type: 'sequence',
containerheight: '500px'
});
});
</script>