0
일부 링크가 있는데 링크를 가리키면 이미지가 표시됩니다. 다음과 비슷한 것을 얻고 싶습니다. http://www.bootsnipp.com/snippets/featured/bootstrap-lightboxjquery를 사용하여 호버에 이미지 표시
클릭 대신 하이퍼 링크를 가리 키기를 원합니다. 아래 코드는 제가 시도한 것입니다. 누군가 내가 올바른 것을 얻을 수 있도록 도와 줄 수 있습니까?
코드 :
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
<link href="bootstrap.min.css" rel="stylesheet" />
<script src="jquery-2.1.0.min.js"></script>
<script src="bootstrap.min.js"></script>
<style>
#lightbox .modal-content {
display: inline-block;
text-align: center;
}
#lightbox .close {
opacity: 1;
color: rgb(255, 255, 255);
background-color: rgb(25, 25, 25);
padding: 5px 8px;
border-radius: 30px;
border: 2px solid rgb(255, 255, 255);
position: absolute;
top: -15px;
right: -55px;
z-index:1032;
}
</style>
</head>
<body>
<script>
$(document).ready(function() {
var $lightbox = $('#lightbox');
$('[data-target="#lightbox"]').hover(function() {
var $img = $(this).find('img'),
src = $img.attr('src'),
alt = $img.attr('alt'),
css = {
'maxWidth': $(window).width() - 100,
'maxHeight': $(window).height() - 100
};
$lightbox.find('.close').addClass('hidden');
$lightbox.find('img').attr('src', src);
$lightbox.find('img').attr('alt', '');
$lightbox.find('img').css(css);
});
$lightbox.on('shown.bs.modal', function (e) {
var $img = $lightbox.find('img');
$lightbox.find('.modal-dialog').css({ 'width': $img.width() });
$lightbox.find('.close').removeClass('hidden');
});
});
</script>
<a href="#" data-toggle="modal" data-target="#lightbox">
Hover here<img src="editedpics/5_china.jpg" style="display:none" />
</a>
<div id="lightbox" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog">
<button type="button" class="close hidden" data-dismiss="modal" aria-hidden="true">x</button>
<div class="modal-content">
<div class="modal-body">
<img src="" alt="" />
</div>
</div>
</div>
</div>
</body>
</html>
코드를 jsbin 또는 jsfiddle에 붙여주십시오. – aisin
코드에 어떤 문제가 있습니까? 그는 JSFiddle이 좋을 것이라고 말했다. – nilsi