Cet article décrit la méthode d'élargir, de réduire et de traîner des images par JS. Partagez-le pour votre référence, comme suit:
var divid; var v_left; var v_top; window.onload = function () {divid = document.getElementById ("block1"); var height1 = images1.height; // la hauteur de l'image var width1 = images1.width; // la largeur de l'image v_left = (document.body.clientwidth-width1) / 2; v_top = (document.body.clientheight-height1) /2;divid.style.left=v_left ;divid.style.top=v_top;} drag = 0; move = 0; // drag object var ie = document.all; var nn6 = document.gelement. isdrag = false; var y, x; var odRagoBj; fonction moveMouse (e) {if (isdrag) {odragobj.style.top = (nn6? nty + e.clienty - y: nty + event.clienty - y) + "px"; odragoBj.style.left = (nn6? ntx + e.clientx - - x) + "px"; return false;}} // glisser la fonction méthode initdrag (e) {var odraghandle = nn6? e.target: event.srcelement; var topElement = "html"; while (odraghandle.tagname! = topElement && odraghandle.classname! = "dragable") {odraghandle = nn6? odraghandle.parentNode: odraghandle.parentElement;} if (odraghandle.classname == "dragable") {isdrag = true; odragobj = odraghandle; nty = paSeInt (odRagoBj.Style.top + 0); y = nn6? E.Clienty: event.clienty; ntx = parseInt (odragobj.style.left + 0); x = nn6? E.ClientX: event.clientx; document.onMouseMove = moveMouse; // document.onMouseUp = Mup; // L'événement se produira lorsque le bouton de la souris est publié;}} document.onmousedown = initdrag; document.onMouseUp = new function ("isDrag = false"); // Move function clickmove (S) {if (s == "up") {wagobj) {up ". parseInt (dragobj.style.top) + 100;} else {if (s == "down") {dragobj.style.top = parseInt (dragobj.style.top) - 100;} else {if (s == "Left") {dragobj.style.left = parseint (sragoBj.style.left) + 100; "Droite") {dragoBj.style.left = paSeInt (dragobj.style.left) - 100;}}}}}} // rétractation multiple smalltit () {// Image de rétrécissement, perdant hot spot height1 = images1.height; width1 = images1.width; images1.height = height1 / 1.1; images1.width = width1 / wideth 1.1;} // Zoom Fonction bigit () {/ * // Zoom l'image, sans perdre Hot Spot var Zoom = ParseInt (images1.style.zoom, 10) || 100; zoom + = event.wheeldelta / 12; if (zoom> 0) {images1.style.zoom = (zoom + 10) + "%";} * /// zoom in et perdent hotspot height1 = images1.height; width1 = images1.width; images1.height = height1 * 1.1; images1.width = width1 * 1.1;} {images1.style.zoom = 100 + "%"; images1.height = images2.Height; images1.width = images2.width; divid.style.left = v_left; divid.style.top = v_top;} fonction featSize () {var width1 = images2,width; var height1 = images2. = height1 / height2; var w = width1 / width2; if (height1 <height2 && width1 <width2) {images1.height = height1; images1.width = width1;} else {if (h> w) {images1.height = height2; images1.width = width1 * hight1 / height1;} else {images1.width = width1; height1 * width2 / width1;}} block1.style.left = 0; block1.style.top = 0;} // roue de souris zoomez et bbimg (o) {/ * var eleleft; var eletop; if (document.documentElement) {eleleft = document.DocumentElement. document.DocumentElement.ScrollTop;} else {eleleft = document.body.scrollleft; eletop = document.body.scrolltop;} v_left + = eleleft; v_top + = eletop; // divid.style.left = v_left; // divid.style.top = v_top; alert (document.documentElement.scrolltop + "---- xxx" + document.body.scrolltop + windows.pageyoff); parseInt (o.style.zoom, 10) || 100; zoom + = event.wheeldelta / 12; if (zoom> 0) {o.style.zoom = zoom + "%";} return false;}Pour plus d'informations sur le contenu lié à JavaScript, veuillez consulter les sujets de ce site: "JavaScript Switching Special Effects and Techniques Résumé", "JavaScript Animation Effets et Résumé des techniques", "Structitual de la recherche JavaScript des compétences en algorithme", "Javascript Algorithme et techniques de compétences javascript Résumé "," Résumé des erreurs et des compétences de débogage JavaScript "et" Résumé de l'utilisation de l'opération mathématique JavaScript "
J'espère que cet article sera utile à la programmation JavaScript de tous.