我對webdev的世界相當陌生,遇到過一個小問題。我想實現一個「縮放」功能,在畫布圖,需要添加Java函數,但我不知道這是要走的路:如何在PHP函數中打印/編碼多行html5/javascript?
print "document.getElementById(\"plus\").addEventListener("click", function(){";
print " scale /= scaleMultiplier;";
print " draw(scale, translatePos);";
print "}, false);";
這是添加多行的正確方法的Javascript/html5代碼內的PHP函數?
以防萬一的需要,我的功能:
function draw($num_of_exons, $start_positions, $end_positions, $start_first_exon, $end_last_exon, $target_pos, $coding_region_start, $coding_region_end, $canvas_x){
//Variable initilisations
//variable initialization removed
//Sort out target positions
//variable initialization removed
//Main Diagram
print "<canvas id=\"$canvas_x\" width=$CANVAS_WIDTH height=$CANVAS_HEIGHT style=\"border:1px solid #c3c3c3;\">";
print "Your browser does not support the HTML5 canvas tag.";
print "</canvas>";
print "<script>";
print "var c = document.getElementById(\"$canvas_x\");";
print "var ctx = c.getContext(\"2d\");";
print "ctx.fillStyle = \"#273c61\";"; // colour
//CODING REGION
print "ctx.fillStyle = \"#80d04b\";"; //rect colour
print "ctx.fillRect($coding_start,$CODING_REGION_POSITION_CANVAS,($coding_end - $coding_start), $CODING_REGION_HEIGHT);"; //draw rectangle
for($x = 0; $x < $num_of_exons; $x++) {
$start_pos = $start_positions[$x];
$start_pos = scale($start_pos, $start_first_exon, $end_last_exon, $new_range_min, $new_range_max);
$end_pos = $end_positions[$x];
$end_pos = scale($end_pos, $start_first_exon, $end_last_exon, $new_range_min, $new_range_max);
print "ctx.fillStyle = \"#41BFFF\";"; //rect colour
print "ctx.shadowOffsetX = 4;";
print "ctx.shadowOffsetY = 4;";
print "ctx.shadowBlur = 1;";
print "ctx.shadowColor = \"rgba(0, 0, 0, 0.5)\";";
print "ctx.fillRect($start_pos,$ITEM_POSITION_CANVAS,($end_pos - $start_pos),$RECT_HEIGHT);"; //draw rectangle
drawexonlines($x, $end_positions, $start_first_exon, $end_last_exon, $new_range_min, $new_range_max, $start_pos, $line_offset);
}
printtargets($target_pos_split_start, $start_first_exon, $target_pos_split_end, $end_last_exon, $new_range_min, $new_range_max, $ITEM_POSITION_CANVAS, $RECT_HEIGHT);
print "</script>";
}
感謝
感謝您的反饋!肯定幫了很多! –