Jquery keyup函数非常慢。我正在输出图像上的文字。但输出很慢。
以下是我运行的html,JS,PHP代码。代码在我这边运行正常,但问题是写一封信几乎是5到10秒。有没有办法加快这个过程。请帮助。
jQuery(document).ready(function(){
//PURE PATH TO IMAGE GENERATING PHP FILE
var base = jQuery(".preview img").attr("src");
//GATHER IMAGE FOR FIRST TIME
jQuery(".preview img").attr("src",base+'?'+jQuery("#realtime-form").serialize());
//KEYUP EVENT AND NEW IMAGE GATHER
jQuery("#realtime-form input,textarea").stop().keyup(function(){
jQuery(".preview img").attr("src",base+'?'+jQuery("#realtime-form").serialize());
});
});
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript" src="http://nameonbirthdaycake.com/scripts/client-side.js"></script>
<div id="mainwrapper" class="preview">
<div id="box-1" class="box">
<img class="downloadable" src="http://nameonbirthdaycake.com/scripts/write.php?user_input=Enter+the+Name&postid=7">
</div>
<form id="realtime-form" action="" method="post"><strong>Enter the Name</strong>
<input id="realtime-form" maxlength="12" name="user_input" type="text" value="Enter the Name"/>
</form></div>
<?php
header ('Content-type: image/png');
if(isset($_GET["postid"])){
$post=(int)$_GET["postid"];
if ($post==7){
$userinput = $_GET["user_input"];
$image=imagecreatefrompng(__DIR__ . "/images/bg.png");
$font = __DIR__ . '/fonts/PR8Charade.ttf';
$col1 = imagecolorallocate($image, 129, 125,11);
$text_size1 = 36;
$xposition1 = 245;
$yposition1 = 380;
$angeldirection1 = 50;
imagettftext($image, $text_size1, $angeldirection1, $xposition1, $yposition1, $col1, $font, $userinput);
imagepng($image);
imagedestroy($image);
}
}
?>