Hi I'm having an issue with Lightbox where it will duplicate my images from my gallery. for example if I put in a row of 3 images, it will display 3 images on the screen, but when clicked on, it will display 6 images.
Here is some code, to give you a better idea of what i'm doing and what my problem is.
<div class = "gallery"> <!------- Image Gallery -------->
<h2> Gallery </h2>
<div class="row"> <!-- Row 1 - contains 3 images -->
<div class="col-lg-4"> <!-- Each Column represents an image -->
<a href = "images/person-2.jpg" data-title = "My First Caption" data-lightbox = "person1">
<img src="images/person-2.jpg" width="200px" class="img-responsive"/>
</a>
</div>
<div class="col-lg-4">
<a href="images/person-2.jpg" data-title = "My Second Caption" data-lightbox = "person1">
<img src="images/person-2.jpg" width = "200px" class="img-responsive"/>
</a>
</div>
<div class="col-lg-4">
<a href="images/person-3.jpg" data-title = "My Third Caption" data-lightbox = "person1">
<img src="images/person-3.jpg" width="200px" class="img-responsive"/>
</a>
</div>
</div><!--Row 1 ends -->
<div class = "row"> <!-- row 2 - contains 3 images -->
<div class = "col-lg-4">
<a href = "images/person-1.jpg" data-title = "caption 1" data-lightbox = "person1">
<img src = "images/person-1.jpg" width = "200px" class = "img-responsive"/>
</a>
</div>
<div class = "col-lg-4">
<a href = "images/person-2.jpg" data-title = "caption 2" data-lightbox = "person1">
<img src = "images/person-2.jpg" width = "200px" class = "img-responsive"/>
</a>
</div>
<div class = "col-lg-4">
<a href = "images/person-2.jpg" data-title = "caption 3" data-lightbox = "person1">
<img src = "images/person-2.jpg" width = "200px" class = "img-responsive"/>
</a>
</div>
</div><!--Row 2 ends -->
</div>
It shows the 6 images instead of 3 because you are using data-lightbox = "person1" for all 6 images. From the Docs : If you have a group of related images that you would like to combine into a set, use the same data-lightbox attribute value for all of the images.
Simple solution is to use a different data-lightbox value for each group of images you want in a set.
I had a similar trouble with lightbox duplicating images, in my case i had a div with inside it an image, an icon and some text. I set the anchor for lightbox on the external div and it duplicated the image three times (since there were three elements inside it). I found a solution retyping the anchor for each single element with different data-lightbox, and everything worked fine. Hope this can help you sorting out your situation.
From this that showed my image three times:
<div class="col-md-3 wow fadeInUp" data-wow-delay="0.1s">
<a href="img/campi/campob.jpg" data-lightbox="campob" title="Campo B">
<div class="about-col">
<div class="img">
<img src="img/campi/campob.jpg" alt="" class="img-fluid">
<div class="icon"><i class="ion-ios-search"></i></div>
</div>
<h2 class="title"><a>Campo B</a></h2><br>
</div>
</a>
</div>
To this, that works fine:
<div class="col-md-3 wow fadeInUp">
<div class="about-col">
<div class="img">
<a href="img/campi/campoa.jpg" data-lightbox="campoa2" title="Campo A">
<img src="img/campi/campoa.jpg" alt="" class="img-fluid">
</a>
<a href="img/campi/campoa.jpg" data-lightbox="campoa" title="Campo A">
<div class="icon"><i class="ion-ios-search"></i></div>
</a>
</div>
<h2 class="title">
<a href="img/campi/campoa.jpg" data-lightbox="campoa3" title="Campo A">
Campo A
</a>
</h2>
<br>
</div>
</div>
Related
I have the following snippet of code in html:
<div class="row">
<div class="col-sm-6">
<div class="product-images">
<div class="product-main-img">
<img src="img/product-thumb-13.jpg" alt="">
</div>
<div class="product-gallery">
<img src="img/product-thumb-14.jpg" alt="">
<img src="img/product-thumb-75.jpg" alt="">
<img src="img/product-thumb-76.jpg" alt="">
</div>
</div>
</div>
</div>
I would like to allow users of the website to click on one of the three thumbnails (14,75 and 76) in the "product-gallery" class and allow it to be visualized as main image (like product 13), hence in bigger size, while the other 3 stay smaller.
The process should be applicable to anyone of the three images on click (typical visualization of products in an ecommerce website, where a particular image is made bigger on click and the others stay small).
I have looked online for applicable methods but cannot find the one I am looking for.
Thanks for the help, have a good day!
This can be achieved by adding an onClick event handler for all the secondary images to change the src attribute of the central image. I have used specific ids to select the images from the DOM. Then we flip the image sources.
<div class="row">
<div class="col-sm-6">
<div class="product-images">
<div class="product-main-img">
<img id="primary-img" src="img/product-thumb-13.jpg" alt="">
</div>
<div class="product-gallery">
<img id="secondary-img" src="img/product-thumb-14.jpg" alt="">
<img id="secondary-img" src="img/product-thumb-75.jpg" alt="">
<img id="secondary-img" src="img/product-thumb-76.jpg" alt="">
</div>
</div>
</div>
</div>
window.onload = function(e){
const secondaryImages = document.querySelectorAll("#secondary-img")
const primaryImage = document.getElementById("primary-img")
secondaryImages.forEach((image) => {
image.addEventListener("click", function() {
const backupSrc = primaryImage.src
primaryImage.src = image.src
image.src = backupSrc
})
})
}
EDIT: fixed code bugs (string literals)
I have an image to display thanks to a lighbox.
If I get the image online with a link http there is no problem but if I want to recover an image of the database I encounter a problem. I would like to display the image in the tag as below.
IF you have tracks I thank you in advance. Beautiful day
<a href="https://unsplash.it/1200/768.jpg?image=256" data-toggle="lightbox" data-gallery="gallery" class="col-md-4">
<img src="https://unsplash.it/600.jpg?image=256" class="img-fluid rounded">
</a>
TO
<div class="row" *ngFor="let drawing of drawings;">
<a href="????" data-toggle="lightbox" data-gallery="gallery" class="col-md-4">
<img style="max-width:400px;" *ngIf="drawing.image" [src]="drawing.image">
</a>
</div>
Since you use angular, take advantage of it :
<div class="image-container" (click)="navigate()">
<img src="...">
</div>
navigate() {
const a = document.createElement('a');
a.href = '...';
a.setAttribute('data-toggle', 'lightbox');
a.setAttribute('data-gallery', 'gallery');
a.click();
a.remove();
}
This will work as if you were actually clicking on a link, but you don't actually use alink in your template.
Other than that, I don't see an issue with appending an image to a link :
<a href="google.com" target="_blank">
<img src="https://via.placeholder.com/500x100?text=ImagePlaceholder">
</a>
I am following one of the bootstrap's template and I am dealing with the next problem:
Template
<div class="col-lg-4 col-sm-6">
<a class="portfolio-box" href="img/portfolio/fullsize/1.jpg">
<img class="img-fluid" src="img/portfolio/thumbnails/1.jpg" alt="">
<div class="portfolio-box-caption">
<div class="project-category text-white-50">
Category
</div>
<div class="project-name">
Project Name
</div>
</div>
</a>
</div>
My problem is the following:
`href` in the `<a>` seems to shows in a modal the image in a bigger size, but I am trying to use it as a variable.
I have tried to use ng-ref="myvariable" but it does not happen (either an error)
How could I do it?
Maybe you should do the next:
...
<a class="portfolio-box" href={{ your-variable}}>
...
Value of "your-variable" should be in the component of this template.
I am currently using Vue JS and the data is coming from API .
to call a data from API I use this method {{services.service_picture}}.
But the problem is I am unable to display the image with this method below.
Can you please send some ideas on how to display it using Vue JS
<div id="main" v-cloak>
<div class="col-sm-5">
<p v-for="picture in services.service_picture"></p>
<img :src="path + '/images/services/'+ picture" class="img-circle" alt="Services" /> </div>
</div>
var main = new Vue({
el: "#main",
data: {
services: [],
path: 'https://examplemyapisource.com'
},
});
API from https://examplemyapisource.com
[
{ "service_picture": "18_1516090191.jpg", } ]
You try here:
<div id="main" v-cloak>
<div class="col-sm-5">
<p v-for="picture in services"></p>
<img :src="path + '/images/services/'+ picture.service_picture" class="img-circle" alt="Services" /> </div>
</div>
Credits to Huang Hong
<img :src="path+'/images/services/'+services.service_picture" class="img-circle" alt="Services">
Note the your v-for only includes the element, therfore you cannot use 'picture' inside the element.
<p v-for="picture in services.service_picture"></p>
<img :src="path + '/images/services/'+ picture" class="img-circle" alt="Services" />
You need to make these changes to get a perfect image.
Here you closed the <p> tag before the image.close that <p> tag after image
<div id="main" v-cloak>
<div class="col-sm-5">
<p v-for="picture in services">
<img :src="path + '/images/services/'+ picture.service_picture" class="img-circle" alt="Services" /> </div>
</p>
</div>
I am building a product grid built upon AngularJS data - where there will be images and product details (text)
The text sometimes extends to the 2nd line, causing havoc.
Here is my code:
<div class="row">
<div data-ng-repeat="s in Results">
<div class="col-xs-4">
<a href="#" class="thumbnail">
<div>
<img ng-src="{{s.ProductImage}}" class="img-responsive">
</div>
<div>
{{s.Store}} {{s.Category}} {{s.ProductName}}
</div>
</a>
</div>
<div class="clearfix visible-xs-block"></div>
</div>
</div>
This is what it looks like:
How do I fix it so that <div>s all have the same height?
I tried to look online for solutions, but I think I am 50% there. Please help.
Note: I Don't want to hide content.
This is what I ended up doing for anyone who stumbles on this again in the future.
Javascript
function ResizeToLargestElement(element) {
var maxHeight = -1;
if ($(element).length > 0) {
$(element).each(function () {
maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height();
});
$(element).each(function () {
$(this).height(maxHeight);
});
}
}
Without AngularJS
For those who aren't using AngularJS, just call ResizeToLargestElement() when data changes or the window is resized using
$(window).resize(function() {
ResizeToLargestElement('.AutoResizeToLargestElement');
});`
With AngularJS
The idea is to call the ResizeToLargestElement() function whenever $scope.Results changes or when the window resizes.
To know when $scope.Results changed is easy, but to know when elements (that are bound to it) finished rendering is not easy. To do that, you need a AngularJS directive.
To know when the window re-sizes, use angular.element($window).on('resize', function () {...});
HTML
<div class="row">
<div data-ng-repeat="s in Results" data-ng-repeat-finished> <!--ADDED Directive-->
<div class="col-xs-4">
<a href="#" class="thumbnail AutoResizeToLargestElement"> <!--ADDED Class-->
<div>
<img ng-src="{{s.ProductImage}}" class="img-responsive">
</div>
<div>
{{s.Store}} {{s.Category}} {{s.ProductName}}
</div>
</a>
</div>
<!--REMOVED clearfix-->
</div>
</div>
MyDirectives.js
angular.module('myApp').directive('ngRepeatFinished', function ($timeout) {
return {
restrict: 'A',
link: function (scope, element, attr) {
if (scope.$last === true) {
$timeout(function () {
scope.$emit('ngRepeatFinished');
});
}
}
}
});
mycontroller.js
$scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
ResizeToLargestElement(".AutoResizeToLargestElement");
});
angular.element($window).on('resize', function () {
ResizeToLargestElement(".AutoResizeToLargestElement");
});
Note: this requires you to include $window in the AngularJS dependency list.
I.E. angular.module('myApp').controller('....', ['...., '$window', ....]);
If you want to keep the height of each product dynamic, you will need to split the results into columns. And then use ng-if to put the right items in the right column. Every 3rd item will go into the same column. To set them to different columns, just reduce the $index by 1 for each extra column.
<div class="row">
<div class="col-xs-4">
<div ng-repeat="s in Results"> <a href="#" class="thumbnail" ng-if="$index%3==0">
<div>
<img ng-src="{{s.ProductImage}}" class="img-responsive" />
</div>
<div>{{s.Store}} {{s.Category}} {{s.ProductName}}</div>
</a>
<div class="clearfix visible-xs-block"></div>
</div>
</div>
<div class="col-xs-4">
<div ng-repeat="s in Results"> <a href="#" class="thumbnail" ng-if="($index-1)%3==0">
<div>
<img ng-src="{{s.ProductImage}}" class="img-responsive" />
</div>
<div>{{s.Store}} {{s.Category}} {{s.ProductName}}</div>
</a>
<div class="clearfix visible-xs-block"></div>
</div>
</div>
<div class="col-xs-4">
<div ng-repeat="s in Results"> <a href="#" class="thumbnail" ng-if="($index-2)%3==0">
<div>
<img ng-src="{{s.ProductImage}}" class="img-responsive" />
</div>
<div>{{s.Store}} {{s.Category}} {{s.ProductName}}</div>
</a>
<div class="clearfix visible-xs-block"></div>
</div>
</div>
</div>
You can manually restrict the height of the div and use an overflow. Use something like
<div class="col-xs-4" style="height:200px; overflow: auto;">Content</div>
Or, you could always use a responsive table (<table class="table table-responsive">) for your layout.
The best solution for this problem is to add clearfix class to hidden divs for earch size of viewport. for example:
Large size: i want 6 columns (large desktops)
Medium size: i want 4 columns (Desktops)
Tablets: i want 3 coumns
phones: i want 2 columns
so i have the products list:
<?php $count=1; foreach($productList as $product) : ?>
<div class="item col-xs-6 col-sm-4 col-md-3 col-lg-2">
Picture and description
</div><!-- /item -->
<?php if( ($count%2)==0) {?><div class="clearfix visible-xs-block"></div><?php }?>
<?php if( ($count%3)==0) {?><div class="clearfix visible-sm-block"></div><?php }?>
<?php if( ($count%4)==0) {?><div class="clearfix visible-md-block"></div><?php }?>
<?php if( ($count%6)==0) {?><div class="clearfix visible-lg-block"></div><?php }?>
<?php $count++; endforeach?>