หน้าหลัก โค้ด-บทความ php โค้ด-บทความ javascript โค้ด-บทความ css สารบัญ สารบัญ

ทักทายครับ

สวัสดีครับ หลังจากที่ blog นี้หยุดการอัพเดททบความเกี่ยวกับโค้ดในการใช้ทำเวปไปนานไม่ว่าจะเป็น code php, html, javascript, css, ajax เนื่องจากผมไม่ค่อยมีเวลาจนลืม blog นี้ไปเลย นึกขึ้นได้ตอนปีใหม่ ไปค้นหาใน google แล้วตกใจ เนื่องจาก blog นี้ไปอยู่ลำดับที่ 1 ของการค้นหา ไม่เชื่อลองดู เลยขอถือโอกาสเริ่มต้นใหม่ในช่วงปีใหม่นี้เริ่มอัพเดทบทความตั้งแต่ตอนนี้เป็นต้นไป หวังเป็นอย่างยิ่งว่าจะมีผู้ติดตามบทความของผมต่อไปน่ะครับ ปล.ท่านใดสนใจลงโฆษณาสามารถติดต่อได้ที่ hotcodephp@gmail.com
แสดงบทความที่มีป้ายกำกับ css แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ css แสดงบทความทั้งหมด

22 พ.ค. 2555

การทำข้อความหยุดชั่วคราวระหว่างที่เลื่อนขึ้น (Pausing up-down Scroller)

เป็นการทำให้ข้อความเลื่อนขึ้นแล้วก็หยุดให้เราอ่านสักพัก แล้วก็เลื่อนเปลี่ยนข้อความใหม่ขึ้นมา วนไปเรื่อย ๆ มันจะเหมือนกับการใช้คำสั่ง marquee แต่ marquee ข้อความจะเลื่อนไปเรื่อย ๆ ไม่ได้หยุดให้เราอ่าน ซึ่งจะอ่านทันไม่ทันก็ขึ้นอยู่กับการหน่วงเวลา แต่สำหรับโค้ดตัวนี้จะหยุดอยู่กับที่สักพักให้เราอ่าน ซึ่งมันจะสะดวกต่อคนอ่านมากกว่า ลองดูโค้ดเลยน่ะครับ

วาง code css นี้ไว้ในส่วนของ <head>
<style type="text/css">

/*Example CSS for the two demo scrollers*/

#pscroller1{
width: 200px;
height: 100px;
border: 1px solid black;
padding: 5px;
background-color: lightyellow;
}

#pscroller2{
width: 350px;
height: 20px;
border: 1px solid black;
padding: 3px;
}

#pscroller2 a{
text-decoration: none;
}

.someclass{ //class to apply to your scroller(s) if desired
}

</style>

<script type="text/javascript">

/*Example message arrays for the two demo scrollers*/

var pausecontent=new Array()
pausecontent[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a><br />Comprehensive JavaScript tutorials and over 400+ free scripts!'
pausecontent[1]='<a href="http://www.codingforums.com">Coding Forums</a><br />Web coding and development forums.'
pausecontent[2]='<a href="http://www.cssdrive.com" target="_new">CSS Drive</a><br />Categorized CSS gallery and examples.'

var pausecontent2=new Array()
pausecontent2[0]='<a href="http://www.news.com">News.com: Technology and business reports</a>'
pausecontent2[1]='<a href="http://www.cnn.com">CNN: Headline and breaking news 24/7</a>'
pausecontent2[2]='<a href="http://news.bbc.co.uk">BBC News: UK and international news</a>'

</script>

<script type="text/javascript">

/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}

</script>

แล้วก็วาง code นี้ในส่วนของ <body>
<script type="text/javascript">

//new pausescroller(name_of_message_array, CSS_ID, CSS_classname, pause_in_miliseconds)

new pausescroller(pausecontent, "pscroller1", "someclass", 3000)
document.write("<br />")
new pausescroller(pausecontent2, "pscroller2", "someclass", 2000)

</script>
Read more >>

การแสดงข้อความในแนวตั้ง

การแสดงข้อความในแนวตั้งโดยใช้ CSS เป็นการเพิ่มลูกเล่นในการสร้างเว็บไซต์ของคุณอีกอย่างหนึ่ง ลองมาดูตัวอย่างกันเลยดีกว่า...
การแสดงข้อความแนวตั้งนั้น ไม่ยากอย่างที่คิดเพียงใช้คำสั่ง writing-mode: ตาม code css ตัวอย่างด้านล่าง
<div style="writing-mode: tb-rl">ข้อความแสดงในแนวตั้ง</div>
Read more >>

27 เม.ย. 2555

การทำเมนูแบบเอาเมาส์ชี้ที่เมนูแล้วมีคำอธิบาย

เอาโค้ดนี้วางไว้ในส่วนของ <head></head>



ส่วนอันนี้ไว้ในส่วนของ <body>

Read more >>

25 เม.ย. 2555

การทำ menu แบบ spinmenu

พอดีไปเห็นเมนูแบบนี้มา แปลกดีครับลองใช้ดูน่ะครับ เป็นการใช้ภาษาทั้งภาษา html และภาษา javascript ร่วมกัน









โค้ดก็ตามนี้เลยน่ะครับ
1. spin.htm



2. spinmenu.js

Read more >>

12 เม.ย. 2555

เอาเมาส์ชี้แล้วเปลี่ยนสีตาราง


วิธีการทำเมาส์โอเวอร์แล้วเปลี่ยนสี แถวของตารางง่ายๆๆ จ๊ะ

อันนี้คือเปลี่ยนทั้งแถว
<tr onMouseOver="this.bgColor='#F4F4F4'" onMouseOut ="this.bgColor = ''">

หากอยากเปลี่ยนเฉพาะคอลัมก็นี้เลย
<td  onMouseOver="this.bgColor='#F4F4F4'" onMouseOut ="this.bgColor = ''">
Read more >>

17 มี.ค. 2555

เอา scrollbar ออกจาก textarea ด้วย CSS


<html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
 <title>css textarea scrollbar </title>
 </head>
 <style type="text/css">
.no_scroll{
overflow:hidden;
}
 </style>
 <body>
 <form id="form1" name="form1" method="post" action="">
   <p>ยังไม่กำหนด CSS  </p>
   <p>
     <textarea name="textarea" cols="40" rows="5"> </textarea>
   </p>
   <p>กำหนด CSS  </p>
   <p>
     <textarea name="textarea" class="no_scroll" cols="40" rows="5"> </textarea>
       </p>
 </form>
 </body>
 </html>
Read more >>

16 มี.ค. 2555

ซ่อน link ที่แสดงตรง status bar

เทคนิคนี้ใช้กันมากในหลายๆเว็บคือไม่อยากให้เวลานำ mouse ไปวางไว้ที Link แล้วมีการดู URL ตรง Status Bar Script ด้านล่างคือการซ่อนไม่ให้แสดงออกมา ก็ถือว่าดีทีเดียว

นำ Code ส่วนนี้ไปไว้ระหว่าง TAG HEAD
<script>
function hidestatus(){
window.status=''
return true
}

if (document.layers)
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)

document.onmouseover=hidestatus
document.onmouseout=hidestatus
</script>
Read more >>

15 มี.ค. 2555

การใส่ icon ใน address bar

การใส่ ไอคอนลงใน Address Bar ของ Browser ให้ใส่โค้ดในส่วน HEAD ดังนี้

<HEAD>
  <LINK REL="SHORTCUT ICON" HREF="http://www.mydomain.com/myicon.ico" />
  <TITLE>My Title</TITLE>
</HEAD>

ถ้าวางไอคอนบน root ของระบบให้ใช้ HREF="favicon.ico" และเปลี่ยนไอคอนเป็นชื่อ favicon.ico ด้วย แต่ถ้าวางไว้ที่โฟลเดอร์อื่นหรือใช้ชื่ออื่น ให้อ้าง HREF รวม path ด้วยเช่น HREF="http://www.mydomain.com/myicon.ico"

ให้ใช้ ไอคอนขนาด 16*16 พิกเซลเท่านั้น สามารถสร้างได้จากโปรแกรมสร้าง icon ทั่วไปครับ

โค้ดจาก http://msdn.microsoft.com/library/default.asp?url=/workshop/Author/dhtml/howto/ShortcutIcon.asp
Read more >>

14 มี.ค. 2555

การทำ input ให้อ่านได้อย่างเดียว

ทำช่อง input ให้อ่านได้อย่างเดียว
<input name="name" type="text" size="20" maxlength="25" value='อ่านอย่างเดียว' readonly="true">
Read more >>

9 มี.ค. 2555

การแสดงข้อมูลให้เห็นในหน้าจอ แต่ไม่เห็นตอนสั่งพิมพ์

หากเราต้องการแสดงข้อมูลให้เห็นเฉพาะในหน้าจออย่างเดียว แต่เวลาสั่งพิมพ์งานไม่ต้องการให้พิมพ์ออกมา สามารถแก้ปัญหาได้โดย
โค้ด

<STYLE type=text/css>

#printable { display: block; }

@media print
{
     #non-printable { display: none; }
     #printable { display: block; }
}

</STYLE>


<DIV id=non-printable>
     <CENTER><FONT color=red><B>สิ่งที่จะให้แสดงออกมาทางหน้าจอ แต่ว่าไม่เห็นเวลา Print หน้านี้ออกมา</B></FONT></CENTER>
</DIV>
<BR>
<DIV id=printable>
     <CENTER><FONT color=blue><B>สิ่งที่จะให้แสดงออกมาทางหน้าจอ และจะเห็นเวลา Print หน้านี้ออกมาด้วย</B></FONT></CENTER>
</DIV>

Read more >>

8 มี.ค. 2555

การกำหนดความกว้างของ div

เป็นการกำหนดความกว้างของ div พร้อมขึ้นบรรทัดของข้อความใหม่
โค้ด

<style type="text/css">
.word-wrap {
word-wrap: break-word;
}
</style>

<div style="width:300px;" class="word-wrap">เพื่อให้กระทู้ของคุณถูกจัดอันดับการแสดงผลในอันดับต้นๆและได้คำตอบอย่างรวดเร็วกรุณาLoginก่อนตั้งกระทู้</div>
Read more >>

การกรอกฟอร์มแล้วมี % ความสำเร็จ

เมื่อเรากรอกข้อมูลช่องใดเสร็จก็จะบอก % การกรอกเสร็จ ต้องกรอกจนครบ 100% จึงจะกดปุ่ม submit ได้

โค้ด

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>jQuery Percent Completion Meter</title>

<style type="text/css">
#container {position:relative; width:990px; margin:0 auto;}
</style>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
(function($){
    $.fn.percentComplete = function(selector, color, size, button){
        return this.each(function(){
            var fieldCount = $(selector).length;
            var completeCount = $(selector+'[value != ""][value != "select"]').length;
            var percentComplete = Math.round((completeCount / fieldCount) * 100);
            $(this).empty().append(percentComplete + "% Complete<br><div><div> </div></div>").children("div").css({"width": size, "border": "1px solid"+color}).children("div").css({"width": percentComplete+"%", "background-color":color});
if(percentComplete == '100'){
$(button).attr('disabled',false);
}else{
$(button).attr('disabled',true);
}
        });
    };
})(jQuery);

$("document").ready(function(){
$("#submit").attr('disabled',true);
    $("#completion_meter").percentComplete(".required", "#000000", "200px", "#submit");
    $(":input").blur(function(){
        $("#completion_meter").percentComplete(".required", "#000000", "200px", "#submit");
    });
});
</script>
</head>
<body>

<div id="container">
   
    <br><br>
    <div id="completion_meter"></div>
    <br><br>
   
    <form>
        <div>First Name: <input class="required" id="first_name" name="first_name" type="text" value=""/></div>
        <div>Last Name: <input class="required" id="last_name" name="first_name" type="text" value=""/></div>
        <div>Email: <input class="required" id="email" name="email" type="text" value="" /></div>
        <div>Birthday: <input class="required" id="Birthday" name="birthday" type="text" value="" /></div>
        <div>Address: <input class="required" id="address" name="address" type="text" value="" /></div>
        <div>Do you like Tech Crunch: <select class="required" id="tech_crunch"><option value="select">select</option><option value="yes">yes</option><option value="no">no</option></select></div>
        <div>Description:<br><textarea rows="6" cols="40" class="required" name="description" id="description"></textarea></div>
        <input type="submit" name="submit" id="submit" value="submit" />
    </form>

</div>


</body>
</html>
Read more >>

6 มี.ค. 2555

การตรึงแนวห้วตาราง

เนื่องจากการทำข้อมูลให้แสดงในหน้ารายงานหากข้อมูลมีจำนวนมากเมื่อเราเลื่อนหน้าจอเพื่อดูข้อมูลด่านล่างเราก็จะไม่เห็นว่าข้อมูลที่เราดูเป็นข้อมูลอะไรเพราะเราจะไม่เห็นชื่อของหัวตาราง ทำให้ผมจำเป็นต้องพึ่ง google หาอยู่พักใหญ่ ค้นทั้ง โค้ด php, css และอื่น ๆ ก็เลยเจอโค้ดด่านล่างซึ่งสามารถนำไปใช้ได้ทั้งภาษา html และ ภาษา php  ซึ่งทำให้พอเลื่อนดูข้อมูลแล้วห้วตารางก็จะเลื่อนตาม

Read more >>