Why does my image not pop out? - html

Upon clicking the image, I want the image to pop out and show message. But i don't know how to do it.
<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/lightbox.min.js"></script>
<link href="css/lightbox.css" rel="stylesheet">
<a href="Images/royalpalace.jpg" data-lightbox="image-1" data-title="RoyalPalace">
<img src="Images/royalpalace.jpg" width="19.7%" height="200px">
</a>

You need to link the appropriate files in the given order:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.10.0/js/lightbox.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.10.0/css/lightbox.min.css" rel="stylesheet">
And make sure the image paths are valid.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.10.0/js/lightbox.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.10.0/css/lightbox.min.css" rel="stylesheet">
<a href="https://cdn.pixabay.com/photo/2015/08/11/10/41/royal-palace-883800_960_720.jpg" data-lightbox="image-1" data-title="RoyalPalace">
<img src="https://cdn.pixabay.com/photo/2015/08/11/10/41/royal-palace-883800_960_720.jpg" width="200px">
</a>

Here is one way to do it:
First, move the <img> out of the <a> tag, or else it will redirect the user to another page, then to pop the image out, write this in a js script:
document.getElementsByTagName("img")[0].addEventListener("click", function () {
this.style.display = "none";
alert("Your message here");
})
You can enhance this by giving the <img> an id attribute and then using document.getElementById("<Your img id>") to access it.

Related

Disable click on ".lg-img-wrap" class in Light Gallery

How to disable click on .lg-img-wrap?
I have tried lot of solutions but none seems to work on lightgallery.
Tried 1
$(".lg-img-wrap").children().unbind('click');
Tried 2
$(".noclick").click(function(e) {
e.preventDefault();
e.stopPropagation();
});
Tried 3
pointer-events:none //to a css property
I would like to prevent closing of light gallery when user clicks outside the image.
Black margin is visible when image ratio is not same as that of screen size.
Please check image below for reference.
Light Gallery I am using: https://github.com/sachinchoolur/lightGallery
Add closeable: false to your lightGallery initialization. Here's their API describing that feature.
Working Codepen
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/1.10.0/css/lightgallery.css" integrity="sha512-I/g40Mx7U2Oepd3iHIpQRqdQGJ3vgdw0ix8LxGxX9zKv1MDizjD6dRcJ3PC1qpyfkj4rikVNcpBKcnmuJWUaTQ==" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/1.10.0/js/lightgallery.min.js"></script>
</head>
<div id="lightgallery">
<a href="https://via.placeholder.com/150">
<img src="https://via.placeholder.com/150" />
</a>
</div>
<script type="text/javascript">
$('#lightgallery').lightGallery({
closable: false
});
</script>
</html>
$(".lg-img-wrap").off("click");
or
$(".lg-img-wrap").prop("disabled",true);
or
$('.lg-img-wrap"').click(false);
I hope it works for you. good work.

Can I change img src in html?

It's like
<img src="somesrc" file="filepath" />
The src is not the correct url, how can I load the img using the url in file attribute for all images?
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery
/jquery-1.4.min.js"></script>
</head>
<body>
<img src="wrongsrc" file="http://www.hi-pda.com/forum/uc_server/data/avatar/000/52/56/39_avatar_middle.jpg"></img>
<script >
$("img").each(function(){
var filepath = $(this).prop("file");
if (filepath) this.src=filepath;
});
</script>
</body>
</html>
I change my code to this, but it does not work.
Using jQuery to edit all of your images:
$(function() {
$("img").each(function(){
var filepath = $(this).attr("file");
if (filepath) this.src=filepath;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<img src="wrongsrc" file="http://www.hi-pda.com/forum/uc_server/data/avatar/000/52/56/39_avatar_middle.jpg"></img>
<img src="wrongsrc" file="http://www.hi-pda.com/forum/uc_server/data/avatar/000/52/56/39_avatar_middle.jpg"></img>
<img src="wrongsrc" file="http://www.hi-pda.com/forum/uc_server/data/avatar/000/52/56/39_avatar_middle.jpg"></img>
<img src="wrongsrc" file="http://www.hi-pda.com/forum/uc_server/data/avatar/000/52/56/39_avatar_middle.jpg"></img>
Add an id to each image
For HTML
<img SRC="somesource" id="1" />
<img SRC="somesource" id="2" />
<img SRC="somesource" id="3" />
For JavaScript
(document).ready(function (){
$("img").each(function() {
var id = $(this).attr('id')
$(this).attr('src', ''+id+'_image.png');
});
});
Rename your images like 1_image.PNG, 2_image.PNG and so on
It sounds confusing but may work, inform if it works, on a mobile device so can't test it myself.
The above answer is right, it goes will when I run it in chrome in a PC.But when I put that code in ios, it seems there is a little problem about using jQuery in ios.Maybe I did not using jQuery in the right way.I solved my problem using the method below:
<script type="text/javascript">
var imgs = document.getElementsByTagName("img");
for (var i = 0; i < imgs.length; i++) {
if(imgs[i].getAttribute("file")!=null&&imgs[i].getAttribute("file")!=undefined){
imgs[i].src=imgs[i].getAttribute("file");
}
}
</script>
Please use another version of jQuery and it will work fine.
jQuery("img").each(function(){
var filepath = jQuery(this).attr("file");
if (filepath) this.src=filepath;
});
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<img src="wrongsrc" file="http://www.hi-pda.com/forum/uc_server/data/avatar/000/52/56/39_avatar_middle.jpg">

Smooth scroll foundation5 don't work

I'm using Foundation 5 magellan navigation but smooth scroll doesn't work. In example all is fine: http://foundation.zurb.com/docs/components/magellan.html
My code: http://jsfiddle.net/5LKzf/
<head>
<link rel="stylesheet" href="css/foundation-5.2.2/css/foundation.css" />
<link rel="stylesheet" href="css/foundation-5.2.2/css/normalize.css" />
<script src="css/foundation-5.2.2/js/vendor/modernizr.js"></script>
</head>
<body>
//my link
<li class="item-109 menu-el active"><dd data-magellan-arrival="/"><a href="#/" >Main Page</a></dd></li>
//my anhor
<a class="link-pos" data-magellan-destination="/" name="/"> </a>
<script src="css/foundation-5.2.2/js/vendor/jquery.js"></script>
<script src="css/foundation-5.2.2/js/vendor/fastclick.js"></script>
<script src="css/foundation-5.2.2/js/foundation.min.js"></script>
<script>
$( document ).foundation();
</script>
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/main.js"></script>
</body>
Did I forget to include any files?
According to the docs
"Make sure jquery.js, foundation.js, and foundation.magellan.js have been included on your page before continuing. For example, add the following before the closing tag:"
<script src="js/vendor/jquery.js"></script>
<script src="js/foundation/foundation.js"></script>
<script src="js/foundation/foundation.magellan.js"></script>
According to the code you posted, you are missing the magellan js, which would explain why it doesnt work!
I have worked with Foundation 5, and with some features you need to ensure you include the relevant javascript.
I hope this helps!

CSS Selectors, HTML Markup, What am I missing?

I'm attempting to use a fancy JSslider, with a project I'm working on for school and I can't seem to understand why I can't get it working. It should be simple...
<link href='http://fonts.googleapis.com/css?family=Merienda One' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="coin-slider.min.js"></script>
<div id="wTurkey">
<h1> The Wild Turkey</h1>
<div class="coin-slider">
<a href="" target="_blank">
<img src='images/cotside.jpg'>
<span>
<p>The Wild Turkey</p>
Some text here
</span>
</a>
At the very end of my body tag I have the following
<script type="text/javascript">
$(document).ready(function() {
$('#coin-slider').coinslider({hoverPause: false });
});
</script>
</body>
Here's the original site. http://workshop.rs/2010/04/coin-slider-image-slider-with-unique-effects/ I'm just basicly looking for a second set of eyes to tell me what's wrong.
The problem is with your jQuery selector:
$('#coin-slider')
should be
$('.coin-slider')
The 'dot' denotes a css class rather than an ID (which is denoted by the # symbol)

Iframe Close - Button href

I actually make a homepage. My login-area is in an Iframe, hereĀ“s my code:
<link type="text/css" media="screen" rel="stylesheet" href="colorbox.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="colorbox/jquery.colorbox.js"></script>
<script>
$(document).ready(function(){
$(".example7").colorbox({width:"85,5%", height:"85%",iframe:true});
});
and
<button>Klick</button>
My problem is, that I want the new link not to open in the iframe-window.
How can I do that?
... will open the link in a new page.
See also: https://developer.mozilla.org/en/HTML/Element/a#attr-target