douxian6260 2012-02-20 19:33
浏览 73

我定制的php / jquery gallery lightbox不会在页面加载时居中

I created a custom gallery and it works perfectly in internet explorer however in firefox and chrome it doesn't work like it should. The lightbox doesn't pop up on the clicking the thumbnail link, you have to click it twice, when clicked once the backdrop comes up but not the lightbox, but then on clicking the thumbnail twice it centers and pops up. And I have no clue why, please help.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Album</title>

<script type="text/javascript" src="hftpnyc/js/jquery-1.7.1.min.js"></script>

<link href="albums.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="Website/print.css" rel="stylesheet" type="text/css" media="print"/>

<style type="text/css">
    body {

    } 


    .backdrop
    {   position:fixed;
        top:0px;
        left:0px;
        width:100%;
        height:100%;
        background:black;
        z-index:50;
        display:none;

    }
    .smllpic a {text-decoration:none;}


    .box
    {margin:auto;
    clear:both;
    position:fixed;
    max-height:705px;
    max-width:905px;
    background:black;
    z-index:52;
    padding:0px;
    border:black 1.2px solid;
    overflow:hidden;

    }

    .close
    {
        position:absolute;
        right:6px;
        margin-top:3px;
        cursor:pointer;
        font-size:20px;
        font-family:acens; 
        font-weight:700px;
        font-stretch:narrower;          
        opacity: .3;
    }
    .smllpic img{cursor:pointer; opacity:0.7; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=70); };
        }
    </style>

</head>

<body>

<div id="contentcontainer" style="width:100%;clear:both;">

<div id="wrapper" style="width:981px; height:100%; margin:0px auto;">




<div style="margin:0px auto;width:979px;">
<h2 style="font-family:Tahoma, Geneva, sans-serif; color:#333;border-bottom:#A3308E solid 1px; background-color: #E6E6E6;"> Album  </h2> </div>

<div style="float:right; margin-right:3px;">
<form action="" method="post">
<a href="Albums.php">
<input type="button" name="Uploadmre" value="Upload more" style="border: 1px solid #d0ccc9;right:0px;background: #fff;color: #5f95ef;font-size: 11px;font-weight: 700;height:22px; margin-right:7px;">
</a>
</form>
</div>

<div id="page-wrap" style=" width:918px; margin: 0px auto;clear:both;">  


<?php  
   error_reporting(0);
/* function:  returns files from dir */
function get_files($images_dir,$exts = array('jpeg','gif','png','jpg')) {
$files = array();
if($handle = opendir($images_dir)) {
while(false !== ($file = readdir($handle))) {
  $extension = strtolower(get_file_extension($file));
  if($extension && in_array($extension,$exts)) {
    $files[] = $file;
  }
}
closedir($handle);
}
return $files;
}

/* function:  returns a file's extension */
function get_file_extension($file_name) {
return substr(strrchr($file_name,'.'),1);
}

$images_dir = 'hftpnyc/thumbs/';
$thumbs_dir = 'hftpnyc/thumbs/thumbnails/';
$thumbs_width = 100;
$images_per_row = 11;
$string = "";
/** generate photo gallery **/
$image_files = get_files($images_dir);
if(count($image_files)) {
$index = 0;
foreach($image_files as $index=>$file) {
$index++;
$thumbnail_image = $thumbs_dir.$file;
//if(!file_exists($thumbnail_image)) {
  //$extension = get_file_extension($thumbnail_image);
  //if($extension) {
    //make_thumb($images_dir.$file,$thumbnail_image,$thumbs_width);
  //}

//}

error_reporting(0);

echo '<div class="smllpic" style=" padding: 0px; margin: 0px; border: 1px solid black; display: block; width: 100px; height:100px; float: left; "><a href="'.$images_dir.$file.'" rel="lrgimg" class="lightbox"> <img id="thumbs" src="',$thumbnail_image,'" width="100px"/></a></div>';

 if($index % $images_per_row == 0) { echo '<div class="clear"></div>'; }
 }
}

else {
echo '<p>There are no images in this gallery.</p>';
}


 ?>
</div>
</div>
</div>
<script type="text/javascript">
$(document).height();
$('.backdrop').height($(document).height());

$(document).ready(function(){   
$('.smllpic img').hover(function () {
var $this   = $(this);
$this.stop().animate({'opacity':'1.0'},200);
},function () {
var $this   = $(this);
$this.stop().animate({'opacity':'0.7'},200);
});});

$(window).bind("load", function() {
var preload = new Array();
$(".box").each(function() {
    s = $(this).attr("src").replace(/\.(.+)$/i, "_on.$1");
    preload.push(s)
});
var img = document.createElement('img');
$(img).bind('load', function() {
    if(preload[0]) {
        this.src = preload.shift();
    }
}).trigger('load');
});

$(document).ready(function(){ 
 function centreit(){
//get the height and width of the modal  
var modal_height = $('.box').height();  
 var modal_width = $('.box').width();   
//get the height and width of the page  
var window_width = $(window).width();  
var window_height = $(window).height();
 //calculate top and left offset needed for centering  
var topp = (window_height - modal_height)/2;  
 var left = (window_width - modal_width)/2;  

 //apply new top and left css values  
    $('.box').css({'top' : topp+'px' , 'left' : left+'px', 'right': left+'px','bottom':topp+'px'}); };




$('.lightbox').click(function(e) {
e.preventDefault(); // keeps new page from loading

var thisPicture = $(this).attr('href'); // path to full sized picture, 
function getit(){
$('body').append('<div class="backdrop" label="click to close"></div><div class="box" id="centre" ><div class="close">x</div><div style="cursor:pointer; opacity:1;font-family:Agency FB;margin-top:50%; right:-20px;position:fixed;color:white;font-size:50px; z-index:50;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;-moz-box-shadow:0px 0px 5px #444444;-webkit-box-shadow:0px 0px 5px #444444;box-shadow:0px 0px 5px #444444;">></div><div style="cursor:pointer; opacity:.35;font-family:Agency FB;margin-top:50%; left:-20px; position:absolute; font-size:50px;color:white;  z-index:70;-webkit-border-radius:5px;-moz-border-radius: 5px; border-radius:5px;-moz-box-shadow:0px 0px 5px #444444; -webkit-box-shadow:0px 0px 5px #444444; box-shadow:0px 0px 5px #444444;"><</div><img class="motown" src="'+thisPicture+'" style="max-height:705px;max-width:905px;z-index:50;"/></div>');
};
$(window).resize(function(){
    $('.box').resize();
    $('.motown').resize();
    centreit();
});

     getit();
 centreit(); 
$("html").css("overflow", "hidden");
$('.backdrop').fadeTo(500,0.9);  
$('.box').children().fadeIn(1000);








//$('.backdrop').css({ 'display' : 'block', opacity : 0}); 


$('.close').click(function(){
close_box();});


$('.backdrop').click(function(){
close_box();});


function close_box(){
$('.backdrop').remove();
$('.box').remove();
$("html").css("overflow", "");};

});});
</script>




</body>
</html>
  • 写回答

1条回答 默认 最新

  • douliao7354 2012-03-22 21:43
    关注

    You should try:

    margin: 0 auto 0;
    left: 0;
    right: 0;
    

    To fix the centering. So that would leave you with:

    .box
    {
      margin:0 auto 0;
      left: 0;
      right: 0;
      clear:both;
      position:fixed;
      max-height:705px;
      max-width:905px;
      background:black;
      z-index:52;
      padding:0px;
      border:black 1.2px solid;
      overflow:hidden;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂