Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to pre-load images from a link in php or jquery
    primarykey
    data
    text
    <p>i have searched feverishly for a solution to my gallery, which doesnt apply the centering function to the image as i click it's respective thumbnail. instead i have to click the thumbnail at least twice for the large image to pop up in the center of the page. the gallery is a jquery/php. i have dynamically loaded my thumbnails using php and link them to the respective large image with the same name using php. I am wondering preloading the large image would help this problem if so how can i preload them seeing as though its an entire directory which has alot of pictures, hence why i didnt manually load them. the script is below:</p> <pre><code>&lt;?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 &amp;&amp; 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=&gt;$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 '&lt;div class="smllpic" style=" padding: 0px; margin: 0px; border: 1px solid black; display: block; width: 100px; height:100px; float: left; "&gt;&lt;a href="'.$images_dir.$file.'" rel="lrgimg" class="lightbox"&gt; &lt;img id="thumbs" src="',$thumbnail_image,'" width="100px"/&gt;&lt;/a&gt;&lt;/div&gt;'; if($index % $images_per_row == 0) { echo '&lt;div class="clear"&gt;&lt;/div&gt;'; } } } else { echo '&lt;p&gt;There are no images in this gallery.&lt;/p&gt;'; } ?&gt; &lt;script type="text/javascript"&gt; $(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); }); 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'}); $('.motown').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('&lt;div class="backdrop" label="click to close"&gt;&lt;/div&gt;&lt;div class="box" id="centre" &gt;&lt;div class="close"&gt;x&lt;/div&gt;&lt;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;"&gt;&gt;&lt;/div&gt;&lt;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;"&gt;&lt;&lt;/div&gt;&lt;img class="motown" src="'+thisPicture+'" style="max-height:705px;max-width:905px;" &gt;&lt;/div&gt;'); }; centreit(); $(window).resize(function(){ $('.box').resize(); $('.motown').resize(); centreit(); }); if ($('.smllpic').click()){ 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", "");}; });}); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload