Removing magnifying glass from image
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Added a function to add magnifying glass (.img-magnifier-glass) on button click. Now I want to remove the glass by clicking "cancel" button. I'm confused on how to write this function to work with the "magnify" function.
I tried to create a function that adds a class, and that class would be "display: none" on ".img-magnifier-glass".
function magnify(imgID, zoom)
{
var img, glass, w, h, bw;
img = document.getElementById(imgID);
/*create magnifier glass:*/
glass = document.createElement("DIV");
glass.setAttribute("class", "img-magnifier-glass");
/*insert magnifier glass:*/
img.parentElement.insertBefore(glass, img);
/*set background properties for the magnifier glass:*/
glass.style.backgroundImage = "url('" + img.src + "')";
glass.style.backgroundRepeat = "no-repeat";
glass.style.backgroundSize = (img.width * zoom) + "px " + (img.height * zoom) + "px";
bw = 3;
w = glass.offsetWidth / 2;
h = glass.offsetHeight / 2;
/*execute a function when someone moves the magnifier glass over the image:*/
glass.addEventListener("mousemove", moveMagnifier);
img.addEventListener("mousemove", moveMagnifier);
/*and also for touch screens:*/
glass.addEventListener("touchmove", moveMagnifier);
img.addEventListener("touchmove", moveMagnifier);
function moveMagnifier(e)
{
var pos, x, y;
/*prevent any other actions that may occur when moving over the image:*/
e.preventDefault();
/*get the cursor's x and y positions:*/
pos = getCursorPos(e);
x = pos.x;
y = pos.y;
/*prevent the magnifier glass from being positioned outside the image:*/
if (x > img.width - (w / zoom)) { x = img.width - (w / zoom); }
if (x < w / zoom) { x = w / zoom; }
if (y > img.height - (h / zoom)) { y = img.height - (h / zoom); }
if (y < h / zoom) { y = h / zoom; }
/*set the position of the magnifier glass:*/
glass.style.left = (x - w) + "px";
glass.style.top = (y - h) + "px";
/*display what the magnifier glass "sees":*/
glass.style.backgroundPosition = "-" + ((x * zoom) - w + bw) + "px -" + ((y * zoom) - h + bw) + "px";
}
function getCursorPos(e)
{
var a, x = 0, y = 0;
e = e || window.event;
/*get the x and y positions of the image:*/
a = img.getBoundingClientRect();
/*calculate the cursor's x and y coordinates, relative to the image:*/
x = e.pageX - a.left;
y = e.pageY - a.top;
/*consider any page scrolling:*/
x = x - window.pageXOffset;
y = y - window.pageYOffset;
return { x: x, y: y};
}
}
function onClick()
{
magnify("img1", 1.5);
magnify("img2", 1.5);
magnify("img4", 1.5);
}<div>
<div class="slideshow-container">
<button onclick = "onClick()" id="btn1" type="button" class="btn"> Zoom In</button>
<button onclick = "zoomOut()" id= "btn2" type= "button" class="btn" >Cancel</button>
<div class="img-magnifier-container mySlides">
<img id = "img1" src="img1.jpg" width="800" height="600">
</div>
<div class="img-magnifier-container mySlides">
<img id = "img2" src="img2.jpg" width="800" height="600" >
</div>
<div class="img-magnifier-container mySlides">
<img id = "img4" src="img4.jpg" width="800" height="600">
</div>
</div>javascript html css function
add a comment |
Added a function to add magnifying glass (.img-magnifier-glass) on button click. Now I want to remove the glass by clicking "cancel" button. I'm confused on how to write this function to work with the "magnify" function.
I tried to create a function that adds a class, and that class would be "display: none" on ".img-magnifier-glass".
function magnify(imgID, zoom)
{
var img, glass, w, h, bw;
img = document.getElementById(imgID);
/*create magnifier glass:*/
glass = document.createElement("DIV");
glass.setAttribute("class", "img-magnifier-glass");
/*insert magnifier glass:*/
img.parentElement.insertBefore(glass, img);
/*set background properties for the magnifier glass:*/
glass.style.backgroundImage = "url('" + img.src + "')";
glass.style.backgroundRepeat = "no-repeat";
glass.style.backgroundSize = (img.width * zoom) + "px " + (img.height * zoom) + "px";
bw = 3;
w = glass.offsetWidth / 2;
h = glass.offsetHeight / 2;
/*execute a function when someone moves the magnifier glass over the image:*/
glass.addEventListener("mousemove", moveMagnifier);
img.addEventListener("mousemove", moveMagnifier);
/*and also for touch screens:*/
glass.addEventListener("touchmove", moveMagnifier);
img.addEventListener("touchmove", moveMagnifier);
function moveMagnifier(e)
{
var pos, x, y;
/*prevent any other actions that may occur when moving over the image:*/
e.preventDefault();
/*get the cursor's x and y positions:*/
pos = getCursorPos(e);
x = pos.x;
y = pos.y;
/*prevent the magnifier glass from being positioned outside the image:*/
if (x > img.width - (w / zoom)) { x = img.width - (w / zoom); }
if (x < w / zoom) { x = w / zoom; }
if (y > img.height - (h / zoom)) { y = img.height - (h / zoom); }
if (y < h / zoom) { y = h / zoom; }
/*set the position of the magnifier glass:*/
glass.style.left = (x - w) + "px";
glass.style.top = (y - h) + "px";
/*display what the magnifier glass "sees":*/
glass.style.backgroundPosition = "-" + ((x * zoom) - w + bw) + "px -" + ((y * zoom) - h + bw) + "px";
}
function getCursorPos(e)
{
var a, x = 0, y = 0;
e = e || window.event;
/*get the x and y positions of the image:*/
a = img.getBoundingClientRect();
/*calculate the cursor's x and y coordinates, relative to the image:*/
x = e.pageX - a.left;
y = e.pageY - a.top;
/*consider any page scrolling:*/
x = x - window.pageXOffset;
y = y - window.pageYOffset;
return { x: x, y: y};
}
}
function onClick()
{
magnify("img1", 1.5);
magnify("img2", 1.5);
magnify("img4", 1.5);
}<div>
<div class="slideshow-container">
<button onclick = "onClick()" id="btn1" type="button" class="btn"> Zoom In</button>
<button onclick = "zoomOut()" id= "btn2" type= "button" class="btn" >Cancel</button>
<div class="img-magnifier-container mySlides">
<img id = "img1" src="img1.jpg" width="800" height="600">
</div>
<div class="img-magnifier-container mySlides">
<img id = "img2" src="img2.jpg" width="800" height="600" >
</div>
<div class="img-magnifier-container mySlides">
<img id = "img4" src="img4.jpg" width="800" height="600">
</div>
</div>javascript html css function
what you probably want to do is remove the whole node you created in themagnifyfunction from the DOM. Just do what you did in reverse, but you won't need all the css, that will go away with the node. You should also remove the eventListeners you set up at the same time.
– HolyMoly
Jan 3 at 21:47
remove node: catalin.red/… and remove event listeners: developer.mozilla.org/en-US/docs/Web/API/EventTarget/….
– HolyMoly
Jan 3 at 21:50
add a comment |
Added a function to add magnifying glass (.img-magnifier-glass) on button click. Now I want to remove the glass by clicking "cancel" button. I'm confused on how to write this function to work with the "magnify" function.
I tried to create a function that adds a class, and that class would be "display: none" on ".img-magnifier-glass".
function magnify(imgID, zoom)
{
var img, glass, w, h, bw;
img = document.getElementById(imgID);
/*create magnifier glass:*/
glass = document.createElement("DIV");
glass.setAttribute("class", "img-magnifier-glass");
/*insert magnifier glass:*/
img.parentElement.insertBefore(glass, img);
/*set background properties for the magnifier glass:*/
glass.style.backgroundImage = "url('" + img.src + "')";
glass.style.backgroundRepeat = "no-repeat";
glass.style.backgroundSize = (img.width * zoom) + "px " + (img.height * zoom) + "px";
bw = 3;
w = glass.offsetWidth / 2;
h = glass.offsetHeight / 2;
/*execute a function when someone moves the magnifier glass over the image:*/
glass.addEventListener("mousemove", moveMagnifier);
img.addEventListener("mousemove", moveMagnifier);
/*and also for touch screens:*/
glass.addEventListener("touchmove", moveMagnifier);
img.addEventListener("touchmove", moveMagnifier);
function moveMagnifier(e)
{
var pos, x, y;
/*prevent any other actions that may occur when moving over the image:*/
e.preventDefault();
/*get the cursor's x and y positions:*/
pos = getCursorPos(e);
x = pos.x;
y = pos.y;
/*prevent the magnifier glass from being positioned outside the image:*/
if (x > img.width - (w / zoom)) { x = img.width - (w / zoom); }
if (x < w / zoom) { x = w / zoom; }
if (y > img.height - (h / zoom)) { y = img.height - (h / zoom); }
if (y < h / zoom) { y = h / zoom; }
/*set the position of the magnifier glass:*/
glass.style.left = (x - w) + "px";
glass.style.top = (y - h) + "px";
/*display what the magnifier glass "sees":*/
glass.style.backgroundPosition = "-" + ((x * zoom) - w + bw) + "px -" + ((y * zoom) - h + bw) + "px";
}
function getCursorPos(e)
{
var a, x = 0, y = 0;
e = e || window.event;
/*get the x and y positions of the image:*/
a = img.getBoundingClientRect();
/*calculate the cursor's x and y coordinates, relative to the image:*/
x = e.pageX - a.left;
y = e.pageY - a.top;
/*consider any page scrolling:*/
x = x - window.pageXOffset;
y = y - window.pageYOffset;
return { x: x, y: y};
}
}
function onClick()
{
magnify("img1", 1.5);
magnify("img2", 1.5);
magnify("img4", 1.5);
}<div>
<div class="slideshow-container">
<button onclick = "onClick()" id="btn1" type="button" class="btn"> Zoom In</button>
<button onclick = "zoomOut()" id= "btn2" type= "button" class="btn" >Cancel</button>
<div class="img-magnifier-container mySlides">
<img id = "img1" src="img1.jpg" width="800" height="600">
</div>
<div class="img-magnifier-container mySlides">
<img id = "img2" src="img2.jpg" width="800" height="600" >
</div>
<div class="img-magnifier-container mySlides">
<img id = "img4" src="img4.jpg" width="800" height="600">
</div>
</div>javascript html css function
Added a function to add magnifying glass (.img-magnifier-glass) on button click. Now I want to remove the glass by clicking "cancel" button. I'm confused on how to write this function to work with the "magnify" function.
I tried to create a function that adds a class, and that class would be "display: none" on ".img-magnifier-glass".
function magnify(imgID, zoom)
{
var img, glass, w, h, bw;
img = document.getElementById(imgID);
/*create magnifier glass:*/
glass = document.createElement("DIV");
glass.setAttribute("class", "img-magnifier-glass");
/*insert magnifier glass:*/
img.parentElement.insertBefore(glass, img);
/*set background properties for the magnifier glass:*/
glass.style.backgroundImage = "url('" + img.src + "')";
glass.style.backgroundRepeat = "no-repeat";
glass.style.backgroundSize = (img.width * zoom) + "px " + (img.height * zoom) + "px";
bw = 3;
w = glass.offsetWidth / 2;
h = glass.offsetHeight / 2;
/*execute a function when someone moves the magnifier glass over the image:*/
glass.addEventListener("mousemove", moveMagnifier);
img.addEventListener("mousemove", moveMagnifier);
/*and also for touch screens:*/
glass.addEventListener("touchmove", moveMagnifier);
img.addEventListener("touchmove", moveMagnifier);
function moveMagnifier(e)
{
var pos, x, y;
/*prevent any other actions that may occur when moving over the image:*/
e.preventDefault();
/*get the cursor's x and y positions:*/
pos = getCursorPos(e);
x = pos.x;
y = pos.y;
/*prevent the magnifier glass from being positioned outside the image:*/
if (x > img.width - (w / zoom)) { x = img.width - (w / zoom); }
if (x < w / zoom) { x = w / zoom; }
if (y > img.height - (h / zoom)) { y = img.height - (h / zoom); }
if (y < h / zoom) { y = h / zoom; }
/*set the position of the magnifier glass:*/
glass.style.left = (x - w) + "px";
glass.style.top = (y - h) + "px";
/*display what the magnifier glass "sees":*/
glass.style.backgroundPosition = "-" + ((x * zoom) - w + bw) + "px -" + ((y * zoom) - h + bw) + "px";
}
function getCursorPos(e)
{
var a, x = 0, y = 0;
e = e || window.event;
/*get the x and y positions of the image:*/
a = img.getBoundingClientRect();
/*calculate the cursor's x and y coordinates, relative to the image:*/
x = e.pageX - a.left;
y = e.pageY - a.top;
/*consider any page scrolling:*/
x = x - window.pageXOffset;
y = y - window.pageYOffset;
return { x: x, y: y};
}
}
function onClick()
{
magnify("img1", 1.5);
magnify("img2", 1.5);
magnify("img4", 1.5);
}<div>
<div class="slideshow-container">
<button onclick = "onClick()" id="btn1" type="button" class="btn"> Zoom In</button>
<button onclick = "zoomOut()" id= "btn2" type= "button" class="btn" >Cancel</button>
<div class="img-magnifier-container mySlides">
<img id = "img1" src="img1.jpg" width="800" height="600">
</div>
<div class="img-magnifier-container mySlides">
<img id = "img2" src="img2.jpg" width="800" height="600" >
</div>
<div class="img-magnifier-container mySlides">
<img id = "img4" src="img4.jpg" width="800" height="600">
</div>
</div>function magnify(imgID, zoom)
{
var img, glass, w, h, bw;
img = document.getElementById(imgID);
/*create magnifier glass:*/
glass = document.createElement("DIV");
glass.setAttribute("class", "img-magnifier-glass");
/*insert magnifier glass:*/
img.parentElement.insertBefore(glass, img);
/*set background properties for the magnifier glass:*/
glass.style.backgroundImage = "url('" + img.src + "')";
glass.style.backgroundRepeat = "no-repeat";
glass.style.backgroundSize = (img.width * zoom) + "px " + (img.height * zoom) + "px";
bw = 3;
w = glass.offsetWidth / 2;
h = glass.offsetHeight / 2;
/*execute a function when someone moves the magnifier glass over the image:*/
glass.addEventListener("mousemove", moveMagnifier);
img.addEventListener("mousemove", moveMagnifier);
/*and also for touch screens:*/
glass.addEventListener("touchmove", moveMagnifier);
img.addEventListener("touchmove", moveMagnifier);
function moveMagnifier(e)
{
var pos, x, y;
/*prevent any other actions that may occur when moving over the image:*/
e.preventDefault();
/*get the cursor's x and y positions:*/
pos = getCursorPos(e);
x = pos.x;
y = pos.y;
/*prevent the magnifier glass from being positioned outside the image:*/
if (x > img.width - (w / zoom)) { x = img.width - (w / zoom); }
if (x < w / zoom) { x = w / zoom; }
if (y > img.height - (h / zoom)) { y = img.height - (h / zoom); }
if (y < h / zoom) { y = h / zoom; }
/*set the position of the magnifier glass:*/
glass.style.left = (x - w) + "px";
glass.style.top = (y - h) + "px";
/*display what the magnifier glass "sees":*/
glass.style.backgroundPosition = "-" + ((x * zoom) - w + bw) + "px -" + ((y * zoom) - h + bw) + "px";
}
function getCursorPos(e)
{
var a, x = 0, y = 0;
e = e || window.event;
/*get the x and y positions of the image:*/
a = img.getBoundingClientRect();
/*calculate the cursor's x and y coordinates, relative to the image:*/
x = e.pageX - a.left;
y = e.pageY - a.top;
/*consider any page scrolling:*/
x = x - window.pageXOffset;
y = y - window.pageYOffset;
return { x: x, y: y};
}
}
function onClick()
{
magnify("img1", 1.5);
magnify("img2", 1.5);
magnify("img4", 1.5);
}<div>
<div class="slideshow-container">
<button onclick = "onClick()" id="btn1" type="button" class="btn"> Zoom In</button>
<button onclick = "zoomOut()" id= "btn2" type= "button" class="btn" >Cancel</button>
<div class="img-magnifier-container mySlides">
<img id = "img1" src="img1.jpg" width="800" height="600">
</div>
<div class="img-magnifier-container mySlides">
<img id = "img2" src="img2.jpg" width="800" height="600" >
</div>
<div class="img-magnifier-container mySlides">
<img id = "img4" src="img4.jpg" width="800" height="600">
</div>
</div>function magnify(imgID, zoom)
{
var img, glass, w, h, bw;
img = document.getElementById(imgID);
/*create magnifier glass:*/
glass = document.createElement("DIV");
glass.setAttribute("class", "img-magnifier-glass");
/*insert magnifier glass:*/
img.parentElement.insertBefore(glass, img);
/*set background properties for the magnifier glass:*/
glass.style.backgroundImage = "url('" + img.src + "')";
glass.style.backgroundRepeat = "no-repeat";
glass.style.backgroundSize = (img.width * zoom) + "px " + (img.height * zoom) + "px";
bw = 3;
w = glass.offsetWidth / 2;
h = glass.offsetHeight / 2;
/*execute a function when someone moves the magnifier glass over the image:*/
glass.addEventListener("mousemove", moveMagnifier);
img.addEventListener("mousemove", moveMagnifier);
/*and also for touch screens:*/
glass.addEventListener("touchmove", moveMagnifier);
img.addEventListener("touchmove", moveMagnifier);
function moveMagnifier(e)
{
var pos, x, y;
/*prevent any other actions that may occur when moving over the image:*/
e.preventDefault();
/*get the cursor's x and y positions:*/
pos = getCursorPos(e);
x = pos.x;
y = pos.y;
/*prevent the magnifier glass from being positioned outside the image:*/
if (x > img.width - (w / zoom)) { x = img.width - (w / zoom); }
if (x < w / zoom) { x = w / zoom; }
if (y > img.height - (h / zoom)) { y = img.height - (h / zoom); }
if (y < h / zoom) { y = h / zoom; }
/*set the position of the magnifier glass:*/
glass.style.left = (x - w) + "px";
glass.style.top = (y - h) + "px";
/*display what the magnifier glass "sees":*/
glass.style.backgroundPosition = "-" + ((x * zoom) - w + bw) + "px -" + ((y * zoom) - h + bw) + "px";
}
function getCursorPos(e)
{
var a, x = 0, y = 0;
e = e || window.event;
/*get the x and y positions of the image:*/
a = img.getBoundingClientRect();
/*calculate the cursor's x and y coordinates, relative to the image:*/
x = e.pageX - a.left;
y = e.pageY - a.top;
/*consider any page scrolling:*/
x = x - window.pageXOffset;
y = y - window.pageYOffset;
return { x: x, y: y};
}
}
function onClick()
{
magnify("img1", 1.5);
magnify("img2", 1.5);
magnify("img4", 1.5);
}<div>
<div class="slideshow-container">
<button onclick = "onClick()" id="btn1" type="button" class="btn"> Zoom In</button>
<button onclick = "zoomOut()" id= "btn2" type= "button" class="btn" >Cancel</button>
<div class="img-magnifier-container mySlides">
<img id = "img1" src="img1.jpg" width="800" height="600">
</div>
<div class="img-magnifier-container mySlides">
<img id = "img2" src="img2.jpg" width="800" height="600" >
</div>
<div class="img-magnifier-container mySlides">
<img id = "img4" src="img4.jpg" width="800" height="600">
</div>
</div>javascript html css function
javascript html css function
edited Jan 4 at 0:38
Nicolás Alarcón Rapela
1,168824
1,168824
asked Jan 3 at 21:37
KellyKelly
31
31
what you probably want to do is remove the whole node you created in themagnifyfunction from the DOM. Just do what you did in reverse, but you won't need all the css, that will go away with the node. You should also remove the eventListeners you set up at the same time.
– HolyMoly
Jan 3 at 21:47
remove node: catalin.red/… and remove event listeners: developer.mozilla.org/en-US/docs/Web/API/EventTarget/….
– HolyMoly
Jan 3 at 21:50
add a comment |
what you probably want to do is remove the whole node you created in themagnifyfunction from the DOM. Just do what you did in reverse, but you won't need all the css, that will go away with the node. You should also remove the eventListeners you set up at the same time.
– HolyMoly
Jan 3 at 21:47
remove node: catalin.red/… and remove event listeners: developer.mozilla.org/en-US/docs/Web/API/EventTarget/….
– HolyMoly
Jan 3 at 21:50
what you probably want to do is remove the whole node you created in the
magnify function from the DOM. Just do what you did in reverse, but you won't need all the css, that will go away with the node. You should also remove the eventListeners you set up at the same time.– HolyMoly
Jan 3 at 21:47
what you probably want to do is remove the whole node you created in the
magnify function from the DOM. Just do what you did in reverse, but you won't need all the css, that will go away with the node. You should also remove the eventListeners you set up at the same time.– HolyMoly
Jan 3 at 21:47
remove node: catalin.red/… and remove event listeners: developer.mozilla.org/en-US/docs/Web/API/EventTarget/….
– HolyMoly
Jan 3 at 21:50
remove node: catalin.red/… and remove event listeners: developer.mozilla.org/en-US/docs/Web/API/EventTarget/….
– HolyMoly
Jan 3 at 21:50
add a comment |
1 Answer
1
active
oldest
votes
You need to find the added elements and delete them. Since the zoom script gives them all the class name of img-magnifier-glass you can do the following:
function zoomOut() {
var zooms = document.querySelectorAll(".img-magnifier-glass");
for(var x=0;x<zooms.length;x++) {
zooms[x].parentNode.removeChild(zooms[x]);
}
}
Perfect, thank you!
– Kelly
Jan 3 at 23:56
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030142%2fremoving-magnifying-glass-from-image%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to find the added elements and delete them. Since the zoom script gives them all the class name of img-magnifier-glass you can do the following:
function zoomOut() {
var zooms = document.querySelectorAll(".img-magnifier-glass");
for(var x=0;x<zooms.length;x++) {
zooms[x].parentNode.removeChild(zooms[x]);
}
}
Perfect, thank you!
– Kelly
Jan 3 at 23:56
add a comment |
You need to find the added elements and delete them. Since the zoom script gives them all the class name of img-magnifier-glass you can do the following:
function zoomOut() {
var zooms = document.querySelectorAll(".img-magnifier-glass");
for(var x=0;x<zooms.length;x++) {
zooms[x].parentNode.removeChild(zooms[x]);
}
}
Perfect, thank you!
– Kelly
Jan 3 at 23:56
add a comment |
You need to find the added elements and delete them. Since the zoom script gives them all the class name of img-magnifier-glass you can do the following:
function zoomOut() {
var zooms = document.querySelectorAll(".img-magnifier-glass");
for(var x=0;x<zooms.length;x++) {
zooms[x].parentNode.removeChild(zooms[x]);
}
}
You need to find the added elements and delete them. Since the zoom script gives them all the class name of img-magnifier-glass you can do the following:
function zoomOut() {
var zooms = document.querySelectorAll(".img-magnifier-glass");
for(var x=0;x<zooms.length;x++) {
zooms[x].parentNode.removeChild(zooms[x]);
}
}
answered Jan 3 at 21:51
Diodeus - James MacFarlaneDiodeus - James MacFarlane
95.5k29139167
95.5k29139167
Perfect, thank you!
– Kelly
Jan 3 at 23:56
add a comment |
Perfect, thank you!
– Kelly
Jan 3 at 23:56
Perfect, thank you!
– Kelly
Jan 3 at 23:56
Perfect, thank you!
– Kelly
Jan 3 at 23:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030142%2fremoving-magnifying-glass-from-image%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what you probably want to do is remove the whole node you created in the
magnifyfunction from the DOM. Just do what you did in reverse, but you won't need all the css, that will go away with the node. You should also remove the eventListeners you set up at the same time.– HolyMoly
Jan 3 at 21:47
remove node: catalin.red/… and remove event listeners: developer.mozilla.org/en-US/docs/Web/API/EventTarget/….
– HolyMoly
Jan 3 at 21:50