2017-03-07 61 views
0

我試圖在image click的全屏幕上顯示圖像。換句話說O映像的點擊它會全屏顯示爲什麼圖像不能全屏顯示?

我想這樣,但不工作

$(".imageBlock").click(function() { 
    $('.imageBlock').css({'width':'100%','height':'100%','z-index':'9999'}) 
}); 

https://jsbin.com/hayalobixo/1/edit?html,css,js,output

$(function() { 

    var counter = 0; 
    $('.currentPage').text(counter+1); 
    $('#pre').prop('disabled', true); 

    $('#next').click(function() { 
    if (counter < 4) { 
     counter++; 
     $('.imageBlock').hide(); 
     $('.imageBlock').eq(counter).show(); 
    } 
    $('.currentPage').text(counter+1); 
    }) 
    $('#pre').click(function() { 
    if (counter > 0) { 
     counter--; 
     $('.imageBlock').hide(); 
     $('.imageBlock').eq(counter).show(); 
    } 
    $('.currentPage').text(counter+1); 
    }) 

    $('#next, #pre').click(function() { 
    if (counter == 0) { 
     $('#pre').prop('disabled', true); 
    } else if (counter == 4) { 
     $('#next').prop('disabled', true); 
    } else { 
     $('#pre').prop('disabled', false); 
     $('#next').prop('disabled', false); 
    } 
    }) 

    $(".imageBlock").click(function() { 
    $('.imageBlock').css({'width':'100%','height':'100%','z-index':'9999'}) 
}); 

}) 
+0

設定位置絕對其他明智這將需要在其中圖像被放置在容器的高度。 $( 'imageBlock ')的CSS({' 寬度 ':' 100%', '高度': '100%', 'z索引': '9999', '位置': '絕對'});。 –

+0

** [像這樣](https://jsbin.com/bupakoyuta/1/edit?html,css,js,output)**? –

+0

'no' https://jsbin.com/hayalobixo/1/edit?html,css,js輸出 – user944513

回答

0

CSS:

div.imageBlock.full{ 
    position: fixed; 
    top: 0; 
    left: 0; 
    height: 100%; 
    width: 100%; 
} 

JS:

$(".imageBlock").click(function() { 
    $('.imageBlock').addClass("full"); 
}); 
+0

https://jsfiddle.net/snm3e8ob/ – user944513

+0

但我認爲我們需要增加圖像的高度和寬度 – user944513

+0

我更新了https://jsfiddle.net/snm3e8ob/ –