0
我有一個項目頁面,有時有一個關聯的YouTube鏈接。當fancybox在fancybox窗口中點擊時打開鏈接。我的鏈接由#youtube1等的計數器標識。有沒有更好的方式來做到這一點,以便每次循環它都不必重做JavaScript?fancybox YouTube與PHP計數
<?php mysql_data_seek($projects,0); $counter = 1; while ($row_projects = mysql_fetch_assoc($projects)) { ?>
<div class="img<?php $count=$counter++; echo $count; ?>" style="height:212px; overflow:hidden;">
<h3><?php echo $row_projects['project_name']; ?></h3>
<p id="project-content"><?php echo stripslashes($row_projects['project_content']); ?><br><?php if(!empty($row_projects['youtube_link'])) { echo '<a id="youtube'.$count.'" href="'.$row_projects['youtube_link'].'" title="'.$row_projects['project_name'].'" class="link1">View project</a>'; } ?>
<script>
$(document).ready(function() {
$("<?php echo '#youtube'.$count ?>").click(function() {
$.fancybox({
'padding' : 0,
'autoScale' : false,
'transitionIn' : 'fade',
'transitionOut' : 'fade',
'title' : this.title,
'width' : 680,
'height' : 495,
'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
'type' : 'swf',
'swf' : { 'wmode' : 'transparent', 'allowfullscreen' : 'true' }
});
return false;
});
});
</script>
</p>
<p class="font1"><span><?php echo $row_projects['project_bold']; ?></a></span></p>
</div>
<?php } ?>
所以然後在每個循環部分我做你所概述的,並有我fancybox的首選項列在頭部? – Alex