Hej,
Nie wiem jak dodać a href do obrazka ładowanego po klku w diva?
Kombinuje i coś mi nie wychodzi... Może ktoś pomoże?
Mam skrypt, który po kliku w zdjęcie ładuje je w innym divie.
I chce aby po załadowaniu w tym innym divie dodał się tam a href
Potrzebne mi to aby zrobić lightboxa, który się opiera o hrefa.
html:
<img src="img/9-1539533771.jpg" onclick="enlarge(this)">
<img src="img/10-1539533774.jpg" onclick="enlarge(this)">
<img src="img/p1.jpg" onclick="enlarge(this)">
<div id="bigview">
</div>
javascript:
function localFilename(url) // removing path
{
var x = url.lastIndexOf("/");
url = url.slice(x + 1);
return url;
}
// images are loaded asynchronously with no delay
function preloading(url)
{
var xhr=createXHR();
xhr.onreadystatechange=function()
{
if(xhr.readyState == 4)
{
var content = xhr.responseText;
var i = new Image();
i.src = content;
}
};
xhr.open("GET", url , true);
xhr.send(null);
}
function enlarge(element)
{
var name = element.src;
name = localFilename(name);
name = "img/" + name; // restore path and add the new "big-" prefix
// building a string to display the image
var str = "<img src='" + name + "' >";
document.getElementById("bigview").innerHTML = str;
}
W efekcie mam takie coś:
<div id="bigview">
<img src="img/10-1539533774.jpg">
</div>
I własnie tu chce dodać a href