I use the JQuery Cycle slideshow a lot in a bunch of different stuff. It’s always the same deal in the head:
<script type="text/javascript">
$(document).ready(function() {
$('.slideshow').cycle({
fx: 'fade',
etc...'
});
});
</script>
Then the pics in the body:
<div class='slideshow'>
<img src='photo1.jpg' width height />
<img src='photo1.jpg' width height />
<img src='photo1.jpg' width height />
etc...
</div>
This time though, I’m building a search engine for vendors. Each vendor returned needs to have a little slideshow in their display box. I’m using the vendor_id to keep the slideshow classes unique, but I had to move the javascript down into the body, actually part of my query results:
while($rst = mysql_fetch_array( SQL is happening... )) {
print("
<script type='text/javascript'>
$(document).ready(function() {
$('.s$rst[vendor_id]').cycle({
fx: 'fade',
etc...
});
});
</script>
<div class='s$rst[vendor_id]'>
<img src='$rst[prime_image]' width height />
<img src='$rst[second_image]' width height />
<img src='$rst[third_image]' width height />
etc...
</div>
");}
Works just fine, can anyone think of a problem with this method before I button it up and move on to something else? Burning up unnecessary memory or something like that?
Thanks,
J
Why not wrap those calls to
cycle()in a function?You’d save count($rst) times strlen() – strlen(functionname+parameters) and it would look and be alot more clean.
You can even keep your cycle() in the header.. or better.. in a dedicated file.js. (which could even be containing a jquery plugin that wraps the call if you fancy that!)