나는 웹 개발에 익숙하지 않지만 큰 관심을 가지고 있습니다. 그래서 기본적으로 이미지의 축소판이 화면에 표시되고 사용자가 클릭하면 더 크게 표시되는 라이트 박스를 만듭니다. 이제 사용자가 갤러리 이미지/미리보기 이미지를 가리키면 현재 이미지 위에 일부 텍스트가 나타나야하며 일부 애니메이션이 있거나 기본적으로 마우스를 움직여 일부 이벤트가 발생해야하지만이를 수행 할 수 없습니다. 텍스트는 동적으로 추가되거나 이전에 배열이나 그 종류의 것으로 저장되어 있어야합니다. 내 코드를보고 그러한 효과를 얻기 위해 수정하는 방법을 알려주십시오. 그렇게 할 수있는 더 쉽고 쉬운 방법을 알고 있다면 자유롭게 공유하십시오. 정말 고맙습니다!!javascript/jquery를 사용하여 동적으로 이미지의 텍스트를 롤오버하는 방법
HTML :
<div class="gallery">
<ul id="images"></ul>
<div class="lightbox">
<div class='limage'>
</div>
<div class='left'>
</div>
<div class='right'>
</div>
<div class='close'>
x
</div>
</div>
</div>
JAVASCRIPT :
var gallery_slider = new Array();
gallery_slider[0] = "im1.jpg";
gallery_slider[1] = "im2.jpg";
gallery_slider[2] = "im3.jpg";
function displayAllImages() {
var i = 0,
len = gallery_slider.length;
for (; i < gallery_slider.length; i++) {
var img = new Image();
img.src = gallery_slider[i];
img.style.width = '200px';
img.style.height = '120px';
img.style.margin = '3px';
img.style.cursor = 'pointer';
document.getElementById('images').appendChild(img);
}
};
$(function() {
displayAllImages();
});
$(function() {
$('img').click(function() {
var hell = (this).src;
display(hell);
});
});
function display(hello) {
$('header').css('display', 'none'); /*for some other purposes*/
$('.limage').html("<img src=" + hello + " >");
$('.lightbox').css("display", "block");
$('.lightbox').fadeIn();
$('.right').click(function() {
var im = new Array();
var x;
var p;
for (x = 0; x < gallery_slider.length; x++) {
im[x] = gallery_slider[x];
}
for (p = 0; p < im.length; p++) {
if (im[p] == hello) {
break;
} else {
continue;
}
}
if (p >= (im.length - 1)) {
p = -1;
}
$('.limage').fadeOut(0);
$('.limage').html("<img src= " + im[p + 1] + ">");
$('.limage').fadeIn(500);
hello = im[p + 1];
});
$('.left').click(function() {
var im = new Array();
var x;
var p;
for (x = 0; x < gallery_slider.length; x++) {
im[x] = gallery_slider[x];
}
for (p = 0; p < im.length; p++) {
if (im[p] == hello) {
break;
} else {
continue;
}
}
if (p == 0) {
p = (im.length);
}
$('.limage').fadeOut(0);
$('.limage').html("<img src= " + im[p - 1] + ">");
$('.limage').fadeIn(500);
hello = im[p - 1];
});
$('.close').click(function() {
$('.lightbox').fadeOut();
$('header').css('display', 'block'); /*for some other purposes*/
});
};
CSS :
.gallery {
width: 100%;
height: 400px;
overflow: hidden;
margin: auto;
}
.gallery ul {
list-style: none;
}
.lightbox {
background-color: rgba(0, 0, 0, 0.3);
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: none;
z-index: 106;
}
.close {
color: #fff;
border: 1px solid #fff;
border-radius: 100px;
background-color: #000;
position: absolute;
top: 10px;
right: 20px;
padding: 10px;
font-family: firstfont;
font-size: 30px;
z-index: 101;
cursor: pointer;
}
.close:hover {
background-color: #ebebeb;
color: #000;
}
.left {
width: 50%;
height: 100%;
position: absolute;
top: 0;
left: 0;
cursor: pointer;
}
.right {
width: 50%;
height: 100%;
position: absolute;
top: 0;
right: 0;
cursor: pointer;
}
.limage {
position: relative;
margin: auto;
top: 17%;
left: 15%;
max-width: 90%;
max-height: 90%;
}
코딩에 몇 가지 버그가있을 수 있습니다. 조심해. 이 코드는 이미지를 매트릭스로 축소판으로 표시하고 클릭하면 라이트 박스의 슬라이더로 표시하기 위해 작동합니다. hover 기능을 초기 축소판에 추가하는 방법을 알 수 없습니다.
Jsfiddle : http://jsfiddle.net/psd6cbd7/1/
불행히도 귀하의 질문은 너무 광범위합니다. 당신은 단순히 "효과가 있다고"묻는 너무 많은 도움이되는 응답을 얻지 못할 것입니다. 그 대신, 스스로 작동하도록 노력한 다음, 막히거나 온라인상의 특정 질문에 대한 답변을 찾을 수없는 경우 * 매우 구체적인 질문으로 되돌아 가십시오 (힌트 : 가능할 수도 있음).제쳐두고, 때때로 JQuery를 사용하고 가끔은 (예 : displayAllImages) 사용하지 않는 것을 보았습니다. 하나의 프로젝트에 대해 하나 또는 둘 다를 고집 할 것을 제안합니다. – oliakaoil
나는 아직도 노력했다. 나는 누군가가이 코드를 실행하려고 시도하고 응답으로 되돌아 가거나 적어도 그것이 필요한 작업을 수행하기위한 적당한 방법인지를 알려주고 싶다. 이 코드는 이미지를 미리보기 이미지로 표시하고 라이트 박스의 슬라이더를 클릭하면 표시됩니다. hover 기능을 초기 축소판에 추가하는 방법을 알 수 없습니다. 오후 8시 30 분 P.S. displayAllImages는 사용자가 jquery에서 만든 함수이거나 잘못된 것입니까? – Yomesh