Byพิชญ์ พันธุ์สนิท


Html 5 มีความสามารถในการแสดง video และ audio เพิ่มขิ้นมา ดังนั้น preload ในครั้งที่แล้ว ซึ่งช่วยโหลดรูปมาเก็บไว้เท่านั้นอาจจะไม่เพียงพอ เพราะไฟล์วิดีโอใหญ่ ๆ หรือไฟล์เพลงยังโหลดมาไม่ครบ การแสดงผลออกมาจึงไม่สมบูรณ์ตามที่ออกแบบไว้ได้ เครื่องมือที่แนะนำวันนี้คือ jQuery.html5Loader โหลดได้ที่ gianlucaguarini http://www.gianlucaguarini.com/

<!doctype html>
<meta charset="utf-8">
<title>preload jQuery.html5loader</title>
#preload {
	background: #000;
	height: 99%;
	opacity: 0.5;
	width: 99%;
	z-index: 100;

<div id="preload"></div>
<script src="assets/jQuery/jquery.min.js"></script>
<script src="assets/jquery/jQuery.html5loader/js/animations/jQuery.html5Loader.circular.js"></script>
<script src="assets/jQuery/jQuery.html5loader/js/jQuery.html5Loader.min.js"></script>
var images ={};
var loaderAnimation = $('#preload').LoaderAnimation({
		onUpdate: loaderAnimation.update

โดย JavaScript จะอ่านข้อมูลที่ต้องโหลดมาจากข้อมูล json ในไฟล์ preloadHtml5loader.json ผมทำไฟล์ PHP ช่วย generate ไว้ให้แล้ว

Xhtml.co.il 01-Jun-2011 02:31


$extensionType['AUDIO'] = array('aiff', 'au', 'flac', 'l16', 'm4a', 'm4b', 'm4p', 'm4rand', 'm4v', 'mp3', 'oga', 'ogg', 'ogv', 'ogx', 'opus', 'pcm', 'ra', 'ram', 'spx', 'wav', 'wave', 'webm');
$extensionType['IMAGE'] = array('gif', 'ico', 'jfi', 'jfif', 'jif', 'jpe', 'jpeg', 'jpg', 'png', 'svg', 'svgz', 'tif', 'tiff');
$extensionType['SCRIPT'] = array('js', 'json');
$extensionType['TEXT'] = array('css', 'csv', 'htm', 'html', 'txt', 'xml');
$extensionType['VIDEO'] = array('aac', 'dv', 'f4a', 'f4b', 'f4p', 'f4v', 'flv', 'm1a', 'm1v', 'm2a', 'm4a', 'm4b', 'm4p', 'm4r', 'm4v', 'mk3d', 'mka', 'mks', 'mkv', 'mov', 'mp1', 'mp2', 'mp4', 'mpa', 'mpeg', 'mpg', 'mpv', 'oga', 'ogv', 'ogx', 'opus', 'qt', 'spx', 'wav', 'wmv');

function ReadFolderDirectory($dir = 'assets/products', $extensionType, $files)
	$multiple = array();
	if($handler = opendir($dir))
		$dirs = array();
		while (($sub = readdir($handler)) !== FALSE)
			$item = array();
			if ($sub != "." && $sub != ".." && $sub != "Thumb.db" && $sub != "Thumbs.db")
					$pathParts = pathinfo($sub);
					$item['type'] = '';
					foreach($extensionType as $group => $type)
						$ext = strtolower($pathParts['extension']);
						if(array_search($ext, $type) !== FALSE)
							$item['type'] = $group;
					if($item['type'] == 'AUDIO' || $item['type'] == 'VIDEO')
						$multiple[$item['type']][$pathParts['filename']][$ext]['size'] = filesize($dir."/".$sub);
						$multiple[$item['type']][$pathParts['filename']][$ext]['source'] = $dir.'/'.$sub;
						$item['size'] = filesize($dir."/".$sub);
						$item['source'] = $dir.'/'.$sub;
						$files[] = $item;
					$files = ReadFolderDirectory($dir."/".$sub, $extensionType, $files);
		foreach($multiple as $type => $filenames)
			$group = array();
			$group['type'] = $type;
			foreach($filenames as $filename => $exts)
				foreach($exts as $ext => $info)
					$group['sources'][$ext]['size'] = $info['size'];
					$group['sources'][$ext]['source'] = $info['source'];
			$files[] = $group;
	return $files;

$files = array();
$files['files'] = ReadFolderDirectory('assets/products/items', $extensionType, $files);
//echo '<pre>',print_r($lists, true),'</pre>';
header('Content-type: application/json; charset=utf-8');
echo json_encode($files);

Effect ที่มีสามารถเปลี่ยนได้โดยการเปลี่ยนไปเรียกไฟล์ javascript อื่นๆ ใน assets/jquery/jQuery.html5loader/js/animations แทน

About the author

พิชญ์ พันธุ์สนิท administrator

6 Comments so far

WilliamSokPosted on4:10 am - ม.ค. 29, 2014

The next time I learn a weblog, I hope that it doesnt disappoint me as a lot as this one. I imply, I do know it was my choice to read, but I really thought youd have something fascinating to say. All I hear is a bunch of whining about something that you possibly can fix if you werent too busy looking for attention.

WilliamSokPosted on10:02 am - ก.พ. 4, 2014

There’s noticeably a bundle to know about this. I assume you made certain nice factors in options also.

DanSokPosted on7:05 am - ก.พ. 6, 2014

Can I simply say what a relief to seek out someone who really knows what theyre speaking about on the internet. You positively know the best way to deliver a difficulty to gentle and make it important. Extra people need to learn this and perceive this aspect of the story. I cant imagine youre not more widespread because you undoubtedly have the gift.

DanSokPosted on9:07 pm - ก.พ. 6, 2014

Whats up! I just want to give a huge thumbs up for the great data you’ve got here on this post. I can be coming back to your blog for more soon.

ZogSokPosted on8:06 pm - มี.ค. 13, 2014

Oh my goodness! an amazing article dude. Thank you Nevertheless I am experiencing concern with ur rss . Don’t know why Unable to subscribe to it. Is there anyone getting identical rss problem? Anybody who is aware of kindly respond. Thnkx

You must be logged in to post a comment.