I am building a site that uses a plugin to create a gallery view a video feed. In the PHP file that generates the gallery view, I added a play button to display on top of the video thumbnails. While the button displays correctly, the plugin applies the video link directly to the thumbnail image, so if a user clicks directly on the button, it does not open the video modal.
<div class="media-thumb videoPreviewBox">
<div class="videoPreview">
</a><img src="<?php echo $image_path?>" href="#popup_prep" alt="<?php echo $file_src?>" class="<?php echo $playerID?>player_get<?php echo $i?> gallery_thumb" href="<?php echo $file_src?>"/>
<img class="playButtonHover" src="<?php echo $this->getThemePath()?>/images/playButtonHover.png">
<img class="playButton" src="<?php echo $this->getThemePath()?>/images/playButton.png">
</div>
</div>
While I'm not sure why there is a closing tag placed where it is, the plugin seems to work fine. I think the issue is that href="#popup_prep" is applied to the image. I tried to wrap the thumbnail image and play button states in < a href="#popup_prep"> (space added to show tag in post), both with and without the href applied to the image.
I'm stumped and don't want to screw anything up. Hoping a PHP person here can point out what I'm doing wrong. Many thanks!
The rest of this post is information I'm including for due diligence, since I'm not sure how much and what context is needed. First the CSS applied to these elements, followed by the full PHP file for the gallery view.
div.videoPreviewBox {
float: left;
display: inline-block;
width: 21%;
margin: 2%;
margin-top: 0%;
}
#media only screen and (max-width: 594px) {
div.videoPreviewBox {
width: 46%;
}
}
#media only screen and (max-width: 300px) {
div.videoPreviewBox {
width: 96%;
}
}
div.videoPreview {
position: relative;
}
img.videoPreviewImg {
width: 100%;
z-index: 1;
}
img.playButtonHover, img.playButton {
position: absolute;
z-index: 5;
top: 50%;
left: 50%;
margin-top: -24px;
margin-left: -24px;
-webkit-transition: opacity .7s ease-in-out;
-moz-transition: opacity .7s ease-in-out;
-o-transition: opacity .7s ease-in-out;
transition: opacity .7s ease-in-out;
}
div.videoPreview:hover img.playButton {
opacity: 0;
}
div.videoPreviewBox p {
margin-top: 2%;
color: white;
line-height: 18px;
}
.player_wrapper{float: left;}
.player{float: left;clear: both;}
.scroller{margin-bottom: 35px; float: left;clear: both; width: 100%;}
.rssIcon{float: left;clear: both;}
.scroll_item{clear: left; float: left;}
.thumb_img{margin-right: 12px; margin-bottom: 25px; float: left; border-color: white; border-width: 2px; border-style: solid; background-color: #dddddd; height: 135px;}
.preview{ width: 600px; }.play_button{padding: 8px; background-color: #e9e9e9; border-color: #c9c9c9; border-width: 1px; border-style: solid; float: right;}
.rssIcon{width: 100%;}
.gallery_thumb{margin-bottom: 12px; margin-right: 12px; }
.gallery_thumb:hover{cursor: pointer;}
.mejs-container{margin-top: 20px!important}
And the full PHP gallery view file:
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
$btID = $b->getBlockTypeID();
$bt = BlockType::getByID($btID);
$uh = Loader::helper('concrete/urls');
$rssUrl = $controller->getRssUrl($b);
$textHelper = Loader::helper("text");
$fl = Loader::model('file_version');
$uh = Loader::helper('concrete/urls');
$mh = Loader::helper('media_type','promedia');
$bt = BlockType::getByHandle('promedia_list');
$height = '400';
$width = '600';
$spread = 4;
$playerID = rand(0,777777);
if (count($cArray) > 0) { ?>
<div class="scroller">
<div id="media_galery">
<?php
$t = 0;
for ($i = 0; $i < count($cArray); $i++ ) {
$t++;
$file = $cArray[$i];
$remote = null;
$name = $file->getFileName();
$file_path = BASE_URL.DIR_REL.$file->getDownloadURL();
$ak_d = FileAttributeKey::getByHandle('media_date');
$date = $file->getAttribute($ak_d);
$ak_a = FileAttributeKey::getByHandle('media_artwork');
$image = $file->getAttribute($ak_a);
if($image==null){
$image_path=$uh->getBlockTypeAssetsURL($bt).'/tools/mp3.png';
}else{
$image = File::getByID($image->fID);
$image_path=$image->getURL();
}
$file_src = BASE_URL.DIR_REL.$file->getRelativePath();
$ak_s = FileAttributeKey::getByHandle('media_audio');
$audio = $file->getAttribute($ak_s);
if($audio){
$audio_array = $mh->getMediaTypeOutput($audio);
$audio_path = $audio_array['path'];
$file_src = $audio_path;
}
$video = null;
$ak_s = FileAttributeKey::getByHandle('media_video');
$video = $file->getAttribute($ak_s);
if($video){
$video_array = $mh->getMediaTypeOutput($video);
$video_path = $video_array['path'];
//var_dump($video_array['id']);
$image_path = $mh->getMediaThumbnail($video_array['id'],$video_array['type']);
//$video_src = $video_path.'?width='.$width.'&height='.$height;
//$file_src = $video_src;
if($video_array['type'] == 'vimeo'){
$file_src = 'http://player.vimeo.com/video/'.$video_array['id'];
}else{
$file_src = $video_path;
}
}
?>
<div class="media-thumb videoPreviewBox">
<div class="videoPreview">
</a><img src="<?php echo $image_path?>" href="#popup_prep" alt="<?php echo $file_src?>" class="<?php echo $playerID?>player_get<?php echo $i?> gallery_thumb" href="<?php echo $file_src?>"/>
<img class="playButtonHover" src="<?php echo $this->getThemePath()?>/images/playButtonHover.png">
<img class="playButton" src="<?php echo $this->getThemePath()?>/images/playButton.png">
</div>
</div>
<?php
if($t == $spread){
$t=0;
echo '</tr>';
}
}
for($d=$t;$d<$spread;$d++){
echo '<td></td>';
if($t == $spread){
echo '</tr>';
}
}
?>
</div>
</div>
<div style="display: none;">
<div id="popup_prep">
</div>
</div>
<script type="text/javascript">
/*<![CDATA[*/
$(document).ready(function() {
$('.gallery_thumb').fancybox({
width: 'auto',
height: 'auto',
onClosed: function(){
$('video, audio').each(function() {
$(this)[0].player.pause();
});
}
});
});
/*]]>*/
</script>
<script type="text/javascript">
/*<![CDATA[*/
$('.gallery_thumb').click(function(){
$('#popup_prep').html('');
var html = '';
var path = $(this).attr('alt');
//console.log(path);
var extension = path.substr( (path.lastIndexOf('.') +1) );
if(extension){
switch(extension) {
case 'm4v':
case 'mpeg':
case 'mpg':
case 'wmv':
case 'avi':
case 'mov':
case 'flv':
case 'f4v':
case 'mp4':
html = '<video class="player_box" id="play" controls="controls" src="'+path+'" width="<?php echo $width?>" height="<?php echo $height?>"></video><br style="clear: both;"/>';
break;
case 'mp3':
case 'm4a':
html = '<audio class="audioplayer" id="play" src="'+path+'" controls="controls" type="audio/m4a"></audio><br style="clear: both;"/>';
break;
default:
var iFrame = true;
html = '<iframe title="video player" width="<?php echo $width?>px" height="<?php echo $height?>px" src="'+path+'" frameborder="0" allowfullscreen></iframe>';
}
}
$('#popup_prep').append(innerShiv(html));
if(!iFrame){
var player = new MediaElementPlayer('video,audio');
}
});
/*]]>*/
</script>
<?php
}
if(!$previewMode && $controller->rss) {
?>
<div class="rssIcon">
<img src="<?php echo $uh->getBlockTypeAssetsURL($bt, 'rss.png')?>" width="14" height="14" />get this feed
</div>
<link href="<?php echo $rssUrl?>" rel="alternate" type="application/rss+xml" title="<?php echo $controller->rssTitle?>" />
<br/>
<?php
}
if ($paginate && $num > 0 && is_object($_fl)) {
$_fl->displayPaging();
}
?>
For full context, here is the page.
I'm not exactly a php expert, but I notice some problems in this line of code:
</a><img src="<?php echo $image_path?>" href="#popup_prep" alt="<?php echo $file_src?>" class="<?php echo $playerID?>player_get<?php echo $i?> gallery_thumb" href="<?php echo $file_src?>"/>
First of all, I'm not sure why there is a "/a" there. That is normally the end tag of a hyperlink. (if I put the <> there it disappears from the answer and gets read like html so lets pretend the "" is the same as <>).
Secondly, it looks like you got the stuff inside the quotes for href and alt mixed up. href is the link, alt is the description. Unless you want the description to be the same as the image link, but I would recoment something more fitting such as alt="Play Video".
Thirdly, check the number of spaces in the class. For example, if $playerID="123" and $i=1. The class would be the following: 123player_get1 gallery_thumb (notice the space between $i, or in this example the number 1, and gallery_thumb). Again I might be wrong but I don't think that space should be there and it can be fixed by eliminating the space beside the closing php tag.
Fourthly, you have two href="" in this img tag. Like I said I'm not an expert, but I'm assuming the first one need not be there and probably is causing trouble, as href is the link it will take you to when the image is clicked.
Fifthly, I'm not sure if it really matters or not, but normally an img tag doesn't have a /> at the end, it only requires a >.
Try substituting it for this line of code:
img src="<?php echo $image_path ?>" href="<?php echo $file_src ?>" alt="YOUR DESCRIPTION HERE" class="<?php echo $playerID ?>player_get<?php echo $i ?>gallery_thumb">
*edit: If it works make sure you understand why!
Related
I have a sequence of 5 user images that I am stacking horizontally using a z-index. i.e: <img src="xxxx" style="z-index:5;position:relative;"> and then z-index 4...3..etc.
I now want to link these images to the user's 'profile'. If I surround my <img> with an <a> it breaks the formatting. It just shows the images in a line (with the z-indexes still correct(!?)) instead of overlapped. I tried just <img> and also <img> but nothing has worked.
<?php $count = 5; ?>
<?php foreach($today_all_result as $today_all_results) : ?>
<a href="<?php echo BASE_URI; ?>/user/?user=<?php echo $today_all_results->user_id; ?>" style="position:relative;z-index:<?php echo $count; ?>">
<img src='<?php echo BASE_URI; ?>/images/userImages/<?php echo $today_all_results->userPicture; ?>' class="pic-athlete <?php echo $stacked; ?>" style="z-index:<?php echo $count; ?>;position:relative;">
</a>
<?php $count--; ?>
<?php $stacked = "stacked"; ?>
<?php if($count <= 0) break; ?>
<?php endforeach; ?>
Does anyone know how to fix this? Thank you in advance!
Change the style from position: relative; to position: absolute;
img{
height: 100px;
width: 100px;
position: absolute;
}
<img src="" style="background-color: blue; z-index: 10;"/>
<img src="" style="background-color: green; z-index: 2;"/>
<img src="" style="background-color: red; z-index: 3;"/>
Another example:
img{
height: 100px;
width: 100px;
position: absolute;
}
<img src="" style="background-color: blue; z-index: 1;"/>
<img src="" style="background-color: green; z-index: 2; left: 20px; top: 20px;"/>
<img src="" style="background-color: red; z-index: 3;left: 40px; top: 40px;"/>
I have an array of images in php that I am trying to display as a gallery. It is working pretty well, except that the first row of the gallery comes out diagonal, with each image slightly below the one before it.
Here is the code I am using:
CSS
.gallery {
margin: 5px;
border: 1px solid #ccc;
float: left;
display: inline;
width:180px;
height:180px;
}
.gallery:hover {
border: 1px solid #777;
}
.gallery img {
max-height:100%;
max-width:100%;
margin:0 auto;
}
HTML/PHP
<div class="gallery-container">
<?php
$count = 0;
foreach($images as $image) {
echo "<div class='gallery'><a href=''><img src='".$dir.$image."'/></a></div>"; //$dir is the path to the image
if(count % 4 == 0) {
echo "<br>";
}
$count = $count + 1;
}
?>
</div>
Here is a screenshot of the result on the first row:
All the other rows come out fine. Thank you very much for any help.
If you want to do it using float, you would better do that like this:
CSS
.gallery{
margin: 5px;
border: 1px solid #ccc;
float: left;
display: block;
width:180px;
height:180px;
}
.gallery.clear-left{
clear: left;
}
PHP/HTML
<div class="gallery-container">
<?php
$count = 0;
foreach( $images as $image ){?>
<div class="gallery <?php echo( 0 == $count % 4 ? 'clear-left' : '' );?>">
<a href="">
<img src="<?php echo $dir.$image;?>">
</a>
</div>
<?php
$count++;
}
?>
</div>
But there is an even better solution to this, called flex:
Instead of br element render "clear" div
<div style="clear:both"></div>
Have you tried starting the count at 1 instead of 0?
Checkout the resulting html. It is likely that you count is off and the br is being put to the dom too often. This fiddle shows that your desired html and css should work.
<div class='gallery'><a href=''><img src='https://upload.wikimedia.org/wikipedia/commons/b/b2/Hausziege_04.jpg'/></a></div>
<div class='gallery'><a href=''><img src='https://upload.wikimedia.org/wikipedia/commons/b/b2/Hausziege_04.jpg'/></a></div>
<div class='gallery'><a href=''><img src='https://upload.wikimedia.org/wikipedia/commons/b/b2/Hausziege_04.jpg'/></a></div>
<div class='gallery'><a href=''><img src='https://upload.wikimedia.org/wikipedia/commons/b/b2/Hausziege_04.jpg'/></a></div>
<br>
Though, I would consider not using the br, but instead using a containing div:
like this
I want the image to automatically be in horizontal, Should I put another div? because the picture will be save automatically by their position
And here's my CSS:
.row{
display: block;
height:auto;
width:auto;
}
.box_img2{
width: 20px;
padding : 5px;
margin-bottom:5px;
background-color:white;
height:30px;
float:center;
}
And here's my PHP:
<?php
include('../connection/connect.php');
$result = $db->prepare("SELECT * FROM candposition ORDER BY posid ASC");
$result->bindParam(':userid', $res);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
$dsds=$row['posid'];
$resulta = $db->prepare("SELECT sum(votes) FROM candidates WHERE posid= :a");
$resulta->bindParam(':a', $dsds);
$resulta->execute();
for($i=0; $rowa = $resulta->fetch(); $i++){
$dsada=$rowa['sum(votes)'];
}
echo '<div style="margin-top: 18px;">';
echo '<strong>'.$row['pos_name'].' '.'</strong><br>';
$results = $db->prepare("SELECT * FROM candidates,student WHERE candidates.idno=student.idno AND posid= :a ORDER BY votes DESC");
$results->bindParam(':a', $dsds);
$results->execute();
for($i=0; $rows = $results->fetch(); $i++){
if($dsds=='Commissoner'){
echo $rows['prog_id'].$rows['prog_id'].' '.$rows['prog_name'].' = '.$rows['votes'];
}else {
echo "<div class='row'><div class='box_img2'><br>";
echo '<img src="savephp/images/'.$rows['image'].'" width="60" height="70px" />'.' '.$rows['lastname'].', '.$rows['firstname'].'<br>'.' = '.$rows['votes'];
echo '</div>';
}
echo '</div>'.'</div>';
$sdsd=$dsada
?>
<br><br><br><br><br>
<img src="../img/percent.gif"width='<?php echo(100*round($rows['votes']/($sdsd),2)); ?>'height='10'>
<?php
if ($rows['votes']==0){
echo "<br>";}
else {
echo(100*round($rows['votes']/($sdsd),2)); ?>%<br>
<?php
}
echo '</div>';
}
?>
<?php
}
?>
Here's the image:
I want to be like this
Try this:
.box_img2{
width: 20px;
padding : 5px;
background-color:white;
height:30px;
position: fixed; /* or absolute */
top: 50%;
left: 50%;
margin-top: -15px;
margin-left: -10px;
}
Try going down this path, and looking at things like Boostrap's methods to do thumbnail grids, etc., may help you a lot.
Note, the img CSS is more of an either/or thing...one centers, the other will make it fill the 33% of its container.
<style type='text/css'>
.row:before, .row:after { clear:both; }
.img-container {
float:left;
width:33%;
text-align:center;
}
.img-container img { /* if you want it centered */
display:block; margin:0 auto;
}
</style>
<div class='row'>
<?php for($i=0; $rows = $results->fetch(); $i++) { ?>
<div class='img-container'>
<img src="savephp/images/<?php echo $rows['image'] ?>" width="60" height="70px" />
<?php echo $rows['lastname'] ?>, <?php echo $rows['firstname'] ?><br />
=<?php echo $rows['votes'] ?>
</div>
<?php } ?>
</div>
UPDATE I've updated the code above to give a general idea of putting the images into the page. You can build out the rest of the HTML and conditions as needed. The important thing to note is that if you want 3 images across horizontally, make the width of the .img-container 33%. If you only want 2 horizontally, make the width of the .img-container 50%. They will automatically wrap to the next row. Your code was creating a new <div class="row"> for every single entry, which would put each new entry onto its own line rather than having them layout horizontally.
If you hit points where you want a 100% row, you can just give that a different class with width:100% and it will put itself on its own row.
Again, if you lookup how grids work with Bootstrap 3, it will help you get almost any alignment that you want, and I highly recommend using something like that to get going, and then once you're good at creating layouts...then figure out "how" they do it.
I have created a horizontal div that hold a large number of images but has a set width so you have to scroll to see all of the images. I am trying to implement lazy load to speed up load time, but I can get it to work on the first few images, but not the other images just stay gray.
When I remove white-space:nowrap; I can get the lazy load the work correctly, but I lose my single row div.
What would be a good way to have the horizontal scrolling div work with lazy load?
<div class="galleryContainer container-fluid list-inline">
<div class="row ">
<?php
$files = glob("public/img/thumbnail/*.*");
$lFiles = glob("public/img/*.*");
for ($i=0; $i<count($files); $i++)
// ($i=0; $i<count($lFiles); $i++)
{
$image = $files[$i];
$Limage = $lFiles[$i];
// print $image ."<br />";
echo "<div class='img-responsive col-md-3'>";
echo '<div class="container" width: 90%">';
echo '<a href="../'.$Limage .'">
<img width:"300px" height="400px" height="class="lazy" data-original="../'.$image .'" alt="Mural Image"/></a>';
echo '</div>';
echo '</div>';
}
?>
</div>
</div>
<script>
jQuery(document).ready(function ($) {
$(function() {
$("img.lazy").lazyload();
container: $(".galleryContainer")
threshold : 200
effect : "fadeIn"
});
});
</script>
<script src="../public/scripts/jquery.lazyload.js"></script>
<script src="../public/scripts/jquery.scrollstop.js"></script>
Here is my CSS:
.galleryContainer {
margin-top: 2%;
width: 90%;
overflow-x:scroll;
overflow-y:hidden;
}
.profile {
margin-top: 5%;
}
}
.galleryContainer img {
height: 300px;
width: 400px;
}
.fullDrawing img{
height: 217.273px;
width:1440px;
}
.list-inline {
white-space:nowrap;
}
.galleryContainer > .row [class*="col-lg"], .galleryContainer > .row [class*="col-md"], .galleryContainer > .row [class*="col-md"] {
float:none;
display:inline-block;
white-space:normal;
vertical-align:top;
}
#main-content > .row {
overflow-x:scroll;
overflow-y:hidden;
white-space:nowrap;
}
First some small changes:
<img width:"300px" height="400px" height="class="lazy" data-original="../'.$image .'" alt="Mural Image"/>';
should be
<img class="lazy" data-original="../'.$image .'" width:"300" height="400" alt="Mural Image">';
Also i never included my php scripts in html, but maybe the lazylload function triggers too early.
Look at the code loaded by your browser, if the functon triggered correctly the element should look like this:
<img class="lazy" data-original="PATH" width="300" height="400" alt="Mural Image" src="PATH" style="display: inline;">
Last but not least lazyload may have problems with your link around the image, you should test it with a raw image.
When i hover mouse at that time i got the effect but i want to set one image as a by default select when page is load.
Anyone Help me.
Here is my css.
.simpleLens-thumbnails-container a{
display: inline-block;
}
.simpleLens-thumbnails-container a img{
display: block;
}
.all-thumb{
width:50px !important;
}
#demo .img{
border: 5px solid #000;
}
.all-thumb:hover{
box-shadow: 0px 0px 10px #BFCBD5;
}
Here is my PHP code.
<a href="#" id="demo" class="simpleLens-thumbnail-wrapper" data-lens-image="<?php echo $img; ?>" data-bigimage="<?php echo $img; ?>">
<img class="all-thumb" id="demo" src="<?php echo $img; ?>">
</a>
add a class selected to the desired img element like this
$first_item = true;
foreach (............)
{
if($first_item){
<img class="all-thumb selected" id="demo" src="<?php echo $img; ?>">
$first_item = false;
}
else
<img class="all-thumb" id="demo" src="<?php echo $img; ?>">
}
and use this css
.all-thumb.selected, .all-thumb:hover{
box-shadow: 0px 0px 10px #BFCBD5;
}
this will work :)
Add selected to your defult image's class. Desired output for the default image:
<img class="all-thumb selected" id="demo" src="<?php echo $img; ?>">
If you can't hardcode it or do it from the PHP side, use this JQuery code to add the class selected to the first image:
$('.all-thumb:first').addClass('selected');
Then add this JQuery code to your page:
<script>
$(".all-thumb").not(".selected").hover(function(){
$(".all-thumb selected").css("box-shadow","none");
},function(){
$(".all-thumb selected").css("box-shadow","0px 0px 10px #BFCBD5");
});
</script>
It should work. JQuery must be included.
Try this:
Need to add any minimum jquery.
<script src="js/jquery-1.7.1.min.js"></script>
<script>
$(document).ready(function(){
$('.simpleLens-thumbnail-wrapper .all-thumb:first').css('box-shadow', '0px 0px 10px #BFCBD5');
$('.simpleLens-thumbnail-wrapper .all-thumb').mouseover(function(){
$('.simpleLens-thumbnail-wrapper .all-thumb:first').css('box-shadow', 'none');
});
$('.simpleLens-thumbnail-wrapper .all-thumb:first').mouseover(function(){
$('.simpleLens-thumbnail-wrapper .all-thumb:first').css('box-shadow', '0px 0px 10px #BFCBD5');
});
});
</script>
you can also use .hover instead of .mouseover