Once we have outputted all the sliders we intend to, we use the static addScript()
method to add the necessary JavaScript to the document.
This example demonstrates how we can create two slides using our Slide class:
$slide = new Slide();
echo $slide->button('Toggle Slide 1', 'toggle1', 'slide1');
echo $slide->startSlider('slide1', 'class="greyBox"');
echo 'Slide 1';
echo $slide->endSlider();
echo $slide->button('Toggle Slide 2', 'toggle2', 'slide2');
echo $slide->startSlider('slide2', 'class="greyBox"');
echo 'Slide 2';
echo $slide->endSlider();
Slide::addScript();
Notice that we call the static addScript() method at the end with no parameters.
This will add the necessary JavaScript to make our slides work. We should never call
the addScript() method without parameters more than once.
Chapter 9
[ 275 ]
The resultant slides look like this:
When we use the toggle buttons, the corresponding slides will vertically slide in and
out. The buttons don't have to toggle the slides; when we create the buttons we can
specify the button type as toggle, slideIn, slideOut, or hide.
Pages:
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376