Cara Membuat Fungsi Drag Drop di Web dengan HTML5

Seperti yang sudah kita ketahui, perkembangan teknologi web sangat berkembang dengan pesat sejak adanya CSS3 dan HTML5. Kedua bahasa itu memungkinkan kita membuat web interaktif dan kreatif sesuai dengan fantasi kita. Dengan CSS3 kita bisa menciptakan efek-efek desain dan animasi keren, dengan HTML5 kita bisa membuat fungsi-fungsi keren.

Nah, pada posting kali ini, saya akan membahas tutorial membuat fungsi drag dan drop menggunakan HTML5 dengan bantuan javascript. Oke, langsung saja. Pertama-tama kita lihat keseluruhan kodenya :

<!DOCTYPE HTML>
<html>
<head>
<style>
#div1, #div2 {width:300px;height:150px;padding:10px;border:1px solid #aaaaaa;float:left;margin-right:10px;position:relative;overflow:hidden}
</style>
<script>
function allowDrop(ev) {
ev.preventDefault();
}function drag(ev) {
ev.dataTransfer.setData(“text”, ev.target.id);
}function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData(“text”);
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body><p>Drag gambar ke kotak yang lain:</p><div id=”div1″ ondrop=”drop(event)” ondragover=”allowDrop(event)” ondragstart=”drag(event)”>
<img id=”drag1″ src=”http://www.devaradise.com/id/wp-content/uploads/sites/4/2014/11/dragdrop.jpg” draggable=”true” ondragstart=”drag(event)” width=”200″/>
</div>
<br>
<div id=”div2″ ondrop=”drop(event)” ondragover=”allowDrop(event)” ondragstart=”drag(event)”>
</div>
</body>
</html>

Demo :

function allowDrop(ev) {
ev.preventDefault();
}function drag(ev) {
ev.dataTransfer.setData(“text”, ev.target.id);
}function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData(“text”);
ev.target.appendChild(document.getElementById(data));
}

 

Kode diatas bisa langsung anda praktekkan dengan membuat file html baru di komputer anda, lalu menjalankannya di browser. Untuk membuat file html anda cukup buka notepad, paste-kan kode diatas, lalu save as “.html”. Setelah itu, klik 2 kali file html itu untuk dibuka di browser

Penjelasan kode:

1. Pertama, kita mempunyai 2 elemen sebagai wadah untuk gambar yang di drop. Yaitu, tag div dengan id “div1” sebagai wadah gambar sebelum di drag, dan “div2” sebagai wadah untuk gambar ketika di drop. Kedua elemen itu di setting ukuran dan gayanya melalui kode css pada baris kode 5.

2. Kita menambahkan atribut ondrop, ondragover dan ondragstart pada kedua elemen div yang dijadikan sebagai wadah. ketiga atribut itu untuk menjelaskan apa yang bisa/terjadi jika elemen lain(misal:gambar) di drag/drop pada elemen itu. itu adalah atribut HTML5

– ondrop = saat gambar di drop atau ditempatkan di elemen itu
– ondragover = saat gambar yang di drag akan di drop diatas elemen itu
– ondragstart = saat gambar yang ada pada elemen itu di drag untuk dipindahkan ke elemen lain

3. Pada tag img, yaitu tag untuk gambar ditambahkan juga atribut draggable dan ondragstart.

– draggable = atribut untuk mendefinisikan apakah elemen gambar itu bisa di drag atau tidak. nilainya hanya 2, yaitu true atau false

4. Pada masing-masing atribut HTML5 pada elemen-elemen diatas, terdapat beberapa nilai/value yaitu : drop(event), allowDrop(event), drag(event). Ketiga nilai dari atribut ini adalah fungsi yang dibuat dengan javascript pada baris kode 7 sampai 21.

– drop(event) = fungsi untuk drop elemen.
– drag(event) = fungsi untuk drag elemen.
– allowDrop(event) = fungsi untuk mengijinkan bahwa elemen yang di drag dapat di drop atau ditempatkan pada elemen tersebut.

Yap. begitulah.. Selamat mencoba. Kalau bingung, jangan sungkan nanya di komentar.

~Semoga bermanfaat!~

 

viagra natural zithromax dosage cialis cost azithromycin tablets buy levitra online generic cialis azithromycin 500 zovirax cream viagra samples cialis for sale what is lexapro what is ciprofloxacin prescribed for cialis prices viagra vs cialis viagra pillen kruidvat cipro ciprofloxacin hydrochloride viagra online levitra erfahrungen levitra 20 mg von bayer weaning off lexapro side effects lexapro cialis on line how long for lexapro to work ciprofloxacin hydrochloride ophthalmic viagra prices what does ciprofloxacin treat ciprofloxacin 500 buy generic levitra online viagra acyclovir vs valacyclovir tamoxifen azithromycine eg 500 mg bijsluiter acyclovir 800 mg cialis price viagra 100mg azithromycin for uti cialis 10 mg cialis reviews cialis without a doctor’s prescription acyclovir for shingles propecia side effects what is finasteride cialis tadalafil cialis 20mg directions how much does cialis cost azithromycin cost tamoxifen and bone pain free cialis ciprofloxacin nebenwirkungen viagra kaufen what does ciprofloxacin 500mg treat how does lexapro work ciprofloxacin hcl 500 mg lexapro generic name ciprofloxacin dose price cialis escitalopram 10mg cialis patent expiration ciprofloxacin side effects ciprofloxacin coverage cialis professional lexapro and wellbutrin combination therapy sex viagra for women acyclovir side effects cealis ciprofloxacin used for levitra stopping lexapro cipro side effects azithromycin vs erythromycin free viagra is azithromycin azithromycin side effects cialis trial cialis samples azithromycine ciprofloxacin eye drops viagra from canada zoloft vs lexapro side effects of finasteride 5mg cipro antibiotics viagra for men viagra pill lexapro side effects viagra activate zovirax ciprofloxacin 500mg antibiotics acyclovir tamoxifen and foods to avoid lexapro dosages levitra coupons side effects of azithromycin 250 mg zovirax pills zithromax z-pak levitra generic effects of stopping lexapro suddenly antibiotic ciprofloxacin natural viagra online cialis azithromycin for strep throat azithromycin z pak levitra dosage cialis 20mg escitalopram 20 mg escitalopram oxalate utilisation viagra pfizer viagra coupons from pfizer azithromycin 250mg azithromycin coverage viagra medicine lexapro dosing finasteride permanent side effects azithromycin 250 mg treatment ciprofloxacin 500 mg side effects of lexapro 10 mg finasteride side effects viagra on line over the counter viagra what is ciprofloxacin levitra vs viagra for hardness what is acyclovir levitra 10 mg prezzo azithromycin finasteride ciprofloxacin 500mg antibiotics side effects how does acyclovir work cialis coupon cialis coupons from manufacturer ciprofloxacin class azithromycin eye drops cialis effects cialis generic availability levitra prezzo in farmacia cipro 500 levitra bayer 20mg meilleur prix viagra costs cialis samples overnight ciprofloxacin 500mg what does finasteride do lexapro 10mg what is viagra canada viagra effects of stopping finasteride how to wean off lexapro acyclovir dose levitra vs viagra cipro uses lexapro and weight gain in women cialis 20 mg viagra effects ciprofloxacin dosage viagra tablet what is tamoxifen ciprofloxacin 500mg tablets acyclovir 400 mg ciprofloxacin 500 mg for urinary tract infection zovirax for cold sores best price viagra cialis patent expiration 2017 what is azithromycin for finasteride 5 mg tab cipro for uti lexapro coupons what is escitalopram cyalis what is lexapro for viagra substitute escitalopram what is acyclovir used for acyclovir ointment tamoxifen bijwerkingen viagra tablets viagra on line no prec side effects of finasteride cost of cialis side effects of ciprofloxacin 500 mg what is azithromycin used for viagra without a doctor prescription viagra coupons finasteride reviews lexapro side effects in men cialis alternative lexapro weight gain cipro antibiotic azithromycin 500 erfahrungen how long does viagra last what works better than viagra lexapro cipro dangers what is cipro usually prescribed for wholesale cialis what is cipro used for tamoxifen nebenwirkungen zithromax antibiotic cialis 5 mg ciprofloxacin hcl 500 mg side effects cialis pills for sale finasteride effets secondaires viagra cialis cheap cialis 30 day sample cialis online cialis dosage what is cialis azithromycin 250mg tablets 6 pack levitra rezeptfrei deutschland lexapro dosage viagra sans ordonnance cheap cialis generic levitra vardenafil 20mg viagra 100 mg lexapro withdrawal symptoms canadian cialis cialis for bph cialis copay card zovirax dosage buy generic viagra levitra without a doctor prescription viagra en ligne livraison 24h tamoxifen lawsuits viagra soft ciprofloxacin hcl 500 mg tab viagra price viagra vs cialis vs levitra cialis vs viagra first few days on lexapro zithromax 500 mg cialis 5mg cialis daily viagra wikipedia how to wean off lexapro without withdrawals lexapro vs zoloft cialis pricing acyclovir dosing azithromycin 5 day dose pack cialis generic tadalafil cialis free trial viagra wiki ciprofloxacin hcl buy cialis online cipro dosage lexapro manufacturer website cialis 30 day trial coupon viagra nebenwirkungen order viagra women viagra cialis coupon 20 mg tamoxifen interaction buy viagra online ciprofloxacin side effects after age 60 azithromycin and alcohol ciprofloxacin side effects in women acyclovir 200mg tamoxifen side effects cialis pharmacy prices acyclovir 800 mg 5 times a day finasteride for women how to use viagra finasteride results generic levitra azithromycin tablet tamoxifen side effects in women cialis or viagra lexapro 5mg cialis testimonials cialis patent expiration date extended nolvadex cialis website liquid cialis ciprofloxacin 500 mg tabletten azithromycin pregnancy category side effects of acyclovir finasteride 5mg cialis pills celexa vs lexapro what infections does ciprofloxacin treat ciprofloxacin for dogs acyclovir ointment 5 viagra generic side effects of cialis viagra pills lexapro for anxiety escitalopram nebenwirkungen tamoxifen and weight gain lexapro medication azithromycin 500mg tamoxifen langzeitfolgen viagra 50mg acyclovir 400mg acyclovir dosage viagra generico zithromax buying viagra generic lexapro viagra coupon what is tamoxifen used for cialis coupons 2017 finasteride 5mg side effects what bacteria does ciprofloxacin kill revatio vs viagra viamedic cialis cialis voucher acyclovir medication cialis 5mg daily does lexapro cause weight gain cialas lexapro withdrawal finasteride 5 mg viagra 100mg tablets retail price viagra single packs what is finasteride used for what is acyclovir for finasteride side effects in men cialis otc viagra bestellen thuoc azithromycin azithromycin 250 mg cipro drug class azithromycin pregnancy finasteride long term effects generic for cialis lexapro vs celexa generic cialis at walmart how long for azithromycin to take effect is ciprofloxacin a penicillin escitalopram side effects equipe argentine viagra where to buy viagra lexapro benefits for women cialis for women how does cialis work cialis generic ciprofloxacin drops lexapro reviews finasteride dosage generic viagra finasteride 5mg side effects mayo clinic buy cialis cialis for men tamoxifen therapy azithromycin dosage escitalopram effets secondaires viagra canada cialis for daily use vardenafil 20mg what does viagra do ciprofloxacin bnf lexapro 10 mg levitra 20 mg cialis canadian pharmacy pfizer viagra lexapro vs wellbutrin side effects of ciprofloxacin finasteride 5mg tab discount cialis cialis savings card finasteride 1mg lexapro side effects in women lexapro bula acyclovir for cold sores viagra cialis canadian viagra ciprofloxacin uses cialis coupon print azithromycin medscape cialis canada azithromycin uses cilias lexapro generic viagra sex acyclovir cream how to take cialis ciprofloxacin 200 cialis coupon discount viagra lexapro side effects men azithromycin drug class ciprofloxacin ophthalmic solution lexapro para que sirve viagra for sale cialis dosage recommendations escitalopram 10 mg para que sirve cialis dosage strengths common side effects of ciprofloxacin 500 mg female viagra azithromycin 250 post finasteride syndrome viagra vs cialis finasteride efectos secundarios cialis side effects wellbutrin and lexapro ciprofloxacin spc cheap viagra cipro side effects in elderly viagra for sale uk how to get off lexapro levitra 20mg cost per pill side effects of lexapro in women levitra vs viagra levitra 20 mg cost walmart 9 levitra at walmart levitra online viagra 100 what is cipro azithromycin liquid levitra coupon canada cialis ciprofloxacin dosierung levitra 20 mg precio farmacia acyclovir dosage for cold sores ciprofloxacin 250 mg withdrawal from lexapro daily cialis side effects of lexapro cialis vs viagra cialis discount vardenafil vs viagra cialis medication side effects of viagra cialis sample what is ciprofloxacin used for is tamoxifen chemotherapy is azithromycin penicillin cheap levitra finasteride and enlarged prostate lowest cialis prices buy levitra buy viagra levitra 20mg sophia viagra lexapro and weight loss lexapro 20mg tamoxifen citrate finasteride medication viagra alternative azithromycin for pneumonia finasteride vs dutasteride viagra dosage azithromycin pediatric dosing viagra for women lexapro overdose azithromycin without a doctor’s prescription tamoxifen side effects in women over 55 azithromycine 250 mg when will cialis go generic generic for lexapro zovirax ointment side effects of azithromycin generic viagra 100mg azithromycin 500 mg cialis coupons ciprofloxacin 250mg azithromycin class viagra uk azithromycin three times a week lexapro and weight gain viagra vs cialis vs levitra escitalopram 10 mg ciprofloxacin drug class viagra receptfritt tamoxifen cost what does azithromycin treat finasteride for hair loss viagra ohne rezept aus deutschland what is lexapro used for viagra side effects viagra alternatives cialis from canada finasteride tablets is lexapro a controlled substance propecia viagra tesco side effects of tamoxifen viagra ohne rezept auf rechnung finasteride hair loss cost of viagra cialis viagra cost cipro and tendonitis what is azithromycin acyclovir 800 mg for shingles cialis coupons printable levitra prices viagra without a doctor prescription usa generic cialis tadalafil herbal viagra acyclovir 800mg erectile dysfunction cialis how does viagra work

5 Comments

  1. wah makasih udah sharing mas 😀 baru liat drag drop ini dengan HTML 5 Valid 😀

  2. Menjalankannya di bowser. Bowser itu apa?

  3. bisa dicoba nih…

Tinggalkan Balasan

Alamat surel Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *