0
我使用jQuery編寫了一個庫,CSS & HTML,我想添加下一個圖像和以前的圖像按鈕,所以我已經將它們添加到頁面中,並且我已經爲它們製作了功能,但我不知道如何我會做的。這裏是我的代碼,如果任何機構知道這樣做的任何好方法,我會很高興!謝謝! 編輯我還沒有收到回覆,因此我會嘗試提供更多信息,我正嘗試在圖像的左側和右側獲取箭頭,以便我可以轉到上一張和下一張圖像,而且我不會不知道該怎麼做。 在圖庫上的圖像之間切換?
$(document).ready(function(){
\t $('.thumbnail').click(function(){
\t \t $('.backdrop').animate({'opacity':'.5'}, 300, 'linear');
\t \t $('.box').animate({'opacity' : '1.00'}, 300, 'linear');
\t \t $('.box, .selectors, .backdrop').css('display', 'block');
\t \t $('.box').html('<img class="boximg" src="' + $(this).attr('src') + '">');
\t \t //$('.box').html('<img class="boximg" src="' + src + '">');
\t });
\t $('.nextimg').click(function(){
\t \t $('.box').html('<img class="boximg" src="' + '">');
\t });
\t $('.previmg').click(function(){
\t \t $('.box').html('<img class="boximg" src="'+'">');
\t });
\t $('.backdrop').click(function(){
\t \t close_box();
\t });
});
$(document).keydown(function(event){
if (event.keyCode == 27 || event.keyCode == 13){
\t close_box();
};
});
function close_box(){
$('.backdrop, .box').animate({'opacity': '0'}, 300, 'linear', function(){
\t $('.backdrop, .box').css('display', 'none');
\t $('.selectors').css('display', 'none');
});
}
.backdrop{
position: absolute;
display: none;
top: 0px;
left: 0px;
background-color: #000;
opacity: 0;
height: 100%;
width: 100%;
}
.box{
position: absolute;
display: none;
background-color: white;
opacity: 0;
top: 10%;
left: 10%;
width: 80%;
height: 80%;
border-radius: 13px;
}
.close{
float: right;
margin-right: 5px;
}
.boximg {
position: absolute;
top: 3%;
left: 2%;
width: 96%;
height: 94%;
}
.thumbnail{
\t border-radius: 30px;
\t height: 300px;
\t width: 300px;
}
.selectors{
\t display: none;
}
.nextimg{
position: absolute;
right: 3%;
top: 50%;
}
.previmg{
position: absolute;
left: 3%;
top: 50%;
}
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
\t </head>
<body>
\t <div class="images">
\t \t <img class="thumbnail" src="urlttr.jpeg">
\t \t <img class="thumbnail" src="http://www.hdwallpapers.eu/wp/sci-fi-planet-background-1920x1080.jpg">
\t \t <img class="thumbnail" src="http://www.wallpapersdb.org/wallpapers/beach/sunrise_1920x1080.jpg">
\t \t <img class="thumbnail" src="http://free-hq-wallpapers.com/wp-content/uploads/2009/07/New-York-Sunset-1920x1080.jpg">
\t </div>
\t <div class="backdrop"></div>
\t <div class="box"></div>
\t <div class="selectors">
\t \t <image class="nextimg" src="right_arrow.png">
\t \t <image class="previmg" src="left_arrow.png">
\t </div>
\t </body>
</html>
謝謝!但是什麼$ currentImageLink = $ currentImageLink.next('a');和$(function(){})呢?我想爲$(function(){});你必須使它$(document).ready(function(){}); – user3910313 2014-10-28 11:44:03
$(函數(){}) 是 $(文件)。就緒(函數(){}) 只有很短的版本 - $ currentImageLink.next( 'A') 搜索下一個一元素 – progsource 2014-10-28 11:50:38
好的,謝謝! :D – user3910313 2014-10-28 11:54:03