သို့မဟုတ် ပုံ အစုံအတန်း ဖန်တီး စာကြိုး
ပုံ အစုံအတန်း ဖန်တီး သုံးစွဲပါ
ပုံ အစုံအတန်း
ပုံအပေါ် မိုးစားပါ

ပုံ အစုံအတန်း ပြသ:
ပုံ အစုံအတန်း ဖန်တီးပါ
ပထမအစီအစဉ် - အိမ်အော် HTML ထပ်ပေးပါ
<div class="img-zoom-container"> <img id="myimage" src="img_girl.jpg" width="300" height="240" alt="Girl"> <div id="myresult" class="img-zoom-result"></div> </div>
ဒုတိယအစီအစဉ် - ပုံစံ CSS ထပ်ပေးပါ
အကွက်သည် "နှစ်သက်" စောင်းချိန်ရပါသည်。
* {box-sizing: border-box;} .img-zoom-container { position: relative; } .img-zoom-lens { position: absolute; border: 1px solid #d4d4d4; /*set the size of the lens:*/ width: 40px; height: 40px; } .img-zoom-result { border: 1px solid #d4d4d4; /* result div အရွယ် စံပုံရိုက်: */ width: 300px; height: 300px; }
ပုံစံ ၃ - ဂျာမည်ဘာများ ထပ်ထည့်:
function imageZoom(imgID, resultID) { var img, lens, result, cx, cy; img = document.getElementById(imgID); result = document.getElementById(resultID); /* lens ကို ဖန်တီးတာ: */ lens = document.createElement("DIV"); lens.setAttribute("class", "img-zoom-lens"); /* lens ထဲပိုင်း ထိန်းချိန်: */ img.parentElement.insertBefore(lens, img); /* result DIV နှင့် lens အကြား သတ်မှတ်တာ အစားအထား: */ cx = result.offsetWidth / lens.offsetWidth; cy = result.offsetHeight / lens.offsetHeight; /* result DIV အတွက် နောက်ခံ ပုံ အခြေအနေ စံပုံအသစ်: */ result.style.backgroundImage = "url('" + img.src + "')"; result.style.backgroundSize = (img.width * cx) + "px " + (img.height * cy) + "px"; /* အမှတ် ၃ - ပုံနှင့် လှည့်ပုံ အပေါ် မှူးခြူးခဲ့ရသော အခါ အသုံးပြုတာ ပုဂ္ဂိုလ်ကို လုပ်ဆောင်တာ: */ lens.addEventListener("mousemove", moveLens); img.addEventListener("mousemove", moveLens); /* တူညီသော ခွဲခြားသည့် စတင်တန်း: */ lens.addEventListener("touchmove", moveLens); img.addEventListener("touchmove", moveLens); function moveLens(e) {}} var pos, x, y; /* ပုံကြောင်းပေါ်မှ ပြောင်းလဲမှုများအတွက် အခြားလုပ်ဆောင်ခြင်းကို ကာကွယ်ခြင်း: */ e.preventDefault(); /* လက်မှတ်၏ x နှင့် y စက်ပိုင်းကို ရယူခြင်း: */ pos = getCursorPos(e); /* ပြောင်းလဲသော ပုံကြောင်း၏ စက်ပိုင်းကို ခန့်မှန်းခြင်း: */ x = pos.x - (lens.offsetWidth / 2); y = pos.y - (lens.offsetHeight / 2); /* ပုံကြောင်းအပြင်မှ ပြောင်းလဲသော ပုံကြောင်း၏ အခြေအနေကို ကာကွယ်ခြင်း: */ if (x > img.width - lens.offsetWidth) {x = img.width - lens.offsetWidth;} if (x < 0) {x = 0;} if (y > img.height - lens.offsetHeight) {y = img.height - lens.offsetHeight;} if (y < 0) {y = 0;} /* ပြောင်းလဲသော ပုံကြောင်း၏ စက်ပိုင်းကို အစားထိုးခြင်း: */ lens.style.left = x + "px"; lens.style.top = y + "px"; /* ပြောင်းလဲသော ပုံကြောင်းကို ပြသခြင်း: */ result.style.backgroundPosition = "-" + (x * cx) + "px -" + (y * cy) + "px"; } function getCursorPos(e) { var a, x = 0, y = 0; e = e || window.event; /* ပုံကြောင်း၏ x နှင့် y စက်ပိုင်းကို ရယူခြင်း: */ a = img.getBoundingClientRect(); /* လက်မှတ်အား ပုံကြောင်းနှင့် ကိုယ်စား ကို x နှင့် y အစိတ်အစိတ်များ ခန့်မှန်းခြင်း: */ x = e.pageX - a.left; y = e.pageY - a.top; /* စားသပ်ပြီး စားသပ်ရန်: */ x = x - window.pageXOffset; y = y - window.pageYOffset; return {x : x, y : y}; } }
လေးပါးမြောက် - အမြင့်ပေးလုပ်ဆောင်ခြင်း:
<script> imageZoom("myimage", "myresult");