● D e m o s
● P l a y g r o u n d
● T u t o r i a l s
● A r t i c l e s
● C o l l e c t i v e
A u t o m a t i c I m a g e M o n t a g e w i t h j Q u e r y
A r r a n g i n g i m a g e s i n a m o n t a g e l i k e f a s h i o n c a n b e a c h a l l e n g i n g t a s k w h e n c o n s i d e r i n g c e r t a i n c o n s t r a i n t s , l i k e t h e w i n d o w s i z e w h e n u s i n g f u l l s c r e e n , t h e r i g h t i m a g e n u m b e r t o f i l l a l l t h e a v a i l a b l e s p a c e o r a l s o t h e s i z e o f t h e i m a g e s i n u s e . W i t h t h e f o l l o w i n g s c r i p t y o u c a n a u t o m a t i c a l l y c r e a t e a m o n t a g e , e i t h e r f o r a l i q u i d c o n t a i n e r o r a f i x e d s i z e c o n t a i n e r ( i n c l u d i n g f u l l s c r e e n ) , w i t h t h e o p t i o n t o f i l l a l l t h e g a p s .
By M a n o e l a I l i c in P l a y g r o u n d on A u g u s t 3 0 , 2 0 1 1
D e m o
D o w n l o a d
F r o m o u r s p o n s o r : M e c o i s a d i s t r a c t i o n - f r e e s p a c e f o r r e a d i n g a n d d i s c o v e r i n g n e w s l e t t e r s , s e p a r a t e f r o m t h e i n b o x .
A r r a n g i n g i m a g e s i n a m o n t a g e l i k e f a s h i o n c a n b e a c h a l l e n g i n g t a s k w h e n c o n s i d e r i n g c e r t a i n c o n s t r a i n t s , l i k e t h e w i n d o w s i z e w h e n u s i n g f u l l s c r e e n , t h e r i g h t i m a g e n u m b e r t o f i l l a l l t h e a v a i l a b l e s p a c e o r a l s o t h e s i z e o f t h e i m a g e s i n u s e . W i t h t h e f o l l o w i n g s c r i p t y o u c a n a u t o m a t i c a l l y c r e a t e a m o n t a g e , e i t h e r f o r a l i q u i d c o n t a i n e r o r a f i x e d s i z e c o n t a i n e r ( i n c l u d i n g f u l l s c r e e n ) , w i t h t h e o p t i o n t o f i l l a l l t h e g a p s .
H a v i n g a w h i t e s p a c e i n t h e e n d o f t h e c o n t a i n e r c a n , a s w e l l , b e a v o i d e d o p t i o n a l l y . T h e l a s t i m a g e o f t h e m o n t a g e c a n f i l l t h e l e f t s p a c e , s o t h a t t h e m o n t a g e w i l l b e l e f t g a p - l e s s .
A n o t h e r o p t i o n t h a t c a n b e u s e f u l i n s o m e c a s e s i s t h e p o s s i b i l i t y t o o n l y a l l o w t h a t t h e h e i g h t o f a l l i m a g e s w i l l b e t h e h e i g h t o f t h e s m a l l e s t i m a g e , a v o i d i n g t h a t a n y p i c t u r e g e t s p i x e l a t e d / e n l a r g e d . ( T h e d e f a u l t o p t i o n s w i l l a l l o w t h e e n l a r g e m e n t o f s m a l l e r i m a g e s i f t h e r e i s a s i g n i f i c a n t l y h i g h e r n u m b e r o f l a r g e r i m a g e s i n t h e s e t . )
T h e i m a g e s u s e d i n t h e d e m o s a r e b y A n d r e y Y a k o v l e v & L i l i A l e e v a . T h e y a r e l i c e n s e d u n d e r t h e A t t r i b u t i o n - N o n C o m m e r c i a l 3 . 0 U n p o r t e d L i c e n s e .
T h e H T M L s t r u c t u r e
S i m p l y p u t t h e i m a g e s t h a t y o u w a n t t o u s e i n t h e m o n t a g e i n t o a c o n t a i n e r w i t h t h e f o l l o w i n g c l a s s ( t h e I D i s u s e d t o c a l l t h e p l u g i n t h e n ) :
<div class="am-container" id="am-container">
<a href="#"><img src="images/1.jpg" title="Image 1"></img></a>
<a href="#"><img src="images/2.jpg" title="Image 2"></img></a>
<a href="#"><img src="images/3.jpg" title="Image 3"></img></a>
...
</div>
T h e d e f a u l t s t y l e t h a t w e g i v e t o t h i s c o n t a i n e r a n d t h e i m a g e s i s t h e f o l l o w i n g :
.am-wrapper{
float:left;
position:relative;
overflow:hidden;
}
.am-wrapper img{
position:absolute;
outline:none;
}
S i n c e w e d o n ’ t d e f i n e a n y w i d t h f o r t h e c o n t a i n e r , t h e a b o v e e x a m p l e w i l l s h o w t h e m o n t a g e i n f u l l s c r e e n .
I f y o u w o u l d l i k e t o u s e a c o n t a i n e r w i t h a f i x e d w i d t h , y o u c a n s i m p l y a d d a w i d t h .
I n c a s e y o u ’ d l i k e t o h a v e a c o n t a i n e r w i t h a f i x e d h e i g h t a n d w i d t h a n d w i t h a v e r t i c a l s c r o l l b a r , t h e n y o u n e e d t o a d d a n o t h e r w r a p p e r a r o u n d t h e c o n t a i n e r :
<div style="width:800px;height:300px;overflow-y:scroll; margin:40px auto;">
<div class="am-container" id="am-container">
...
</div>
</div>
O p t i o n s
T h e r e a r e s e v e r a l o p t i o n s f o r t h i s p l u g i n . T h e d e f a u l t o n e s a r e t h e f o l l o w i n g :
// If you use percentages (or no width at all)
// for the container's width, then set this to true.
// This will set the body's overflow-y to
// 'scroll' (fix for the scrollbar's width problem)
liquid : true,
// Space between images in pixels
margin : 1,
// The minimum width that a picture should have
minw : 70,
// The minimum height that a picture should have
minh : 20,
// The maximum height that a picture should have
maxh : 250,
// Alternate the height value for every row.
// If true this has priority over defaults.fixedHeight
alternateHeight : false,
// The height will be a random value between 'min' and 'max':
alternateHeightRange : {
min : 100,
max : 300
},
// If the following value is set, this will
// have priority over defaults.minsize.
// All images will have this height:
fixedHeight : null,
// Setting this value will make minw, minh irrelevant.
// Chosen height will be the one of the smallest image
// when this is set to true:
minsize : false,
// If true, there will be no gap in the end
// of the container. The last image will
// fill any white space left:
fillLastRow : false
T h e r e a r e q u i t e s o m e p o s s i b i l i t i e s w i t h t h e s e o p t i o n s a n d s o m e o f t h e m c a n b e s e e n i n t h e d e m o s ( y o u c a n j u m p t o t h e o t h e r d e m o s i n e a c h e x a m p l e ) :
● E x a m p l e 1 : F u l l s c r e e n l i q u i d e x a m p l e w i t h a l t e r n a t i n g h e i g h t s , l a s t i m a g e w i l l f i l l t h e l a s t r o w . R e f r e s h t h e b r o w s e r t o s e e a d i f f e r e n t a r r a n g e m e n t
● E x a m p l e 2 : F u l l s c r e e n l i q u i d e x a m p l e w i t h a l t e r n a t i n g h e i g h t s a n d n o m a r g i n , l a s t i m a g e w i l l f i l l t h e l a s t r o w
● E x a m p l e 3 : F u l l s c r e e n l i q u i d e x a m p l e w i t h a l t e r n a t i n g h e i g h t s a n d b i g g e r m a r g i n , l a s t i m a g e w i l l f i l l t h e l a s t r o w
● E x a m p l e 4 : F i x e d w i d t h c o n t a i n e r e x a m p l e w i t h f i x e d h e i g h t f o r i m a g e s . C l i c k “ l o a d m o r e ” ( e n d o f p a g e ) i n o r d e r t o s e e h o w m o r e i m a g e s c a n b e a d d e d
● E x a m p l e 5 : F i x e d w i d t h a n d h e i g h t o f a w r a p p e r w i t h s c r o l l b a r , l a s t i m a g e w i l l f i l l t h e l a s t r o w
● E x a m p l e 6 : M i n i m u m w i d t h o f i m a g e s w i t h a l t e r n a t i n g h e i g h t s o f r o w s a n d l a r g e m a r g i n , l a s t i m a g e w i l l f i l l t h e l a s t r o w . C l i c k “ l o a d m o r e ” ( e n d o f p a g e ) i n o r d e r t o s e e h o w m o r e i m a g e s c a n b e a d d e d
● E x a m p l e 7 : L i q u i d c o n t a i n e r e x a m p l e w i t h f i x e d h e i g h t f o r i m a g e s . R e s i z e t h e b r o w s e r t o s e e t h e c h a n g e
● E x a m p l e 8 : G u a r a n t e e s t h a t n o i m a g e w i l l b e p i x e l a t e d b y c h o o s i n g t h e m i n i m u m h e i g h t a v a i l a b l e ( l a s t i m a g e c a n n o t f i l l t h e l a s t r o w ) . C l i c k “ l o a d m o r e ” ( e n d o f p a g e ) i n o r d e r t o s e e h o w m o r e i m a g e s c a n b e a d d e d
I n e a c h e x a m p l e y o u c a n v i e w w h i c h o p t i o n s w e r e u s e d t o a c h i e v e t h e l a y o u t / f u n c t i o n a l i t y .
H o p e y o u f i n d i t u s e f u l , f e e d b a c k i s w e l c o m e !
W h y D o C h a i r s H a v e F o u r L e g s ? T h e C o r n e r s t o n e s o f U s a b l e W e b s i t e s
H T M L O n l y – T h e S i g n i f i c a n c e o f P r o p e r M a r k u p i n W e b D e s i g n
T a g g e d w i t h : g r i d m o n t a g e
M a n o e l a i s t h e m a i n t i n k e r e r a t C o d r o p s . W i t h a b a c k g r o u n d i n c o d i n g a n d p a s s i o n f o r a l l t h i n g s d e s i g n , s h e c r e a t e s w e b e x p e r i m e n t s a n d k e e p s f r o n t e n d p r o f e s s i o n a l s i n f o r m e d a b o u t t h e l a t e s t t r e n d s .
● W e b s i t e
●
● D r i b b b l e
● I n s t a g r a m
● G i t h u b
S t a y i n t h e l o o p : G e t y o u r d o s e o f f r o n t e n d t w i c e a w e e k
👾 H e y ! L o o k i n g f o r t h e l a t e s t i n f r o n t e n d ? T w i c e a w e e k , w e ' l l d e l i v e r t h e f r e s h e s t f r o n t e n d n e w s , w e b s i t e i n s p o , c o o l c o d e d e m o s , v i d e o s a n d U I a n i m a t i o n s r i g h t t o y o u r i n b o x .
Z e r o f l u f f , a l l q u a l i t y , t o m a k e y o u r M o n d a y s a n d T h u r s d a y s m o r e c r e a t i v e !
G r a b a C o d r o p s S i g n a t u r e T - S h i r t f e a t u r i n g o u r b r a n d - n e w l o g o d e s i g n ! G e t a n e x c l u s i v e 2 0 % d i s c o u n t w i t h C O D R O P S T R I B E 2 0
C o m m e n t s a r e c l o s e d .
I s i t p o s s i b l e t o “ c h a n g e ” t h e s c r i p t s o i t d o e s n ’ t c r o p t h e p i c t u r e s w h e n t h e y a r e f o r c e d s m a l l e r , b u t j u s t “ r e s i z e s ” ?
H e l l o ! T h a n k s f o r t h i s g r e a t s c r i p t ! I h a v e s o m e t r o u b l e s w i t h l i n k s . H o w c a n I m a k e < a h r e f =
" l i n k " r e l = " n o f o l l o w " >
a r o u n d e v e r y ? E v e r y i m g s h o u l d h a v e u n i q u e l i n k . W h e n I w r i t e < a h r e f
= " l i n k " r e l = " n o f o l l o w " > < / a >
s c r i p t d o e s n ’ t w o r k ( (
h e y m a n ~ t h i s s c r i p t j u s t c a n o n l y b e r u n i n a s e p a r a t e D I V
I h o p e t o a c h i e v e t h e s a m e f u n c t i o n a l i t y i n m u l t i p l e D I V , w h a t t o d o ?
w h o c a n h e l p m e f i x t h i s ?
h t t p : / / j s f i d d l e . n e t / B 5 s A k / 2 4 /
H i . G r e a t s c r i p t . I ’ m d o i n g a g a l l e r y d i v i d e d i n t o s e c t i o n s , e v e r y s e c t i o n a “ m o n t a g e ” d i v . H o w e v e r , o n l y t h e f i r s t d i v i s “ t r a n s f o r m e d ” i n t o a m o n t a g e . I s t h e r e a w a y t o g e t a l l m o n t a g e d i v s t o t r a n s f o r m ? I t w o r k s i f I w r a p a l l t h e s e c t i o n s i n t h e m o n t a g e d i v , b u t t h e n i t c l u m p s a l l t h e i m a g e s t o g e t h e r a n d I w a n t e v e r y s e c t i o n t o b e s e p a r a t e .
T h a n k s .
S o l v e d i f m y s e l f :
$ ( w i n d o w ) . l o a d ( f u n c t i o n ( ) {
$ ( ‘ . c o n t a i n e r ’ ) . e a c h ( f u n c t i o n ( ) {
v a r $ c o n t a i n e r = $ ( t h i s ) ,
$ i m g s = $ c o n t a i n e r . f i n d ( ‘ i m g ’ ) . h i d e ( ) ,
t o t a l I m g s = $ i m g s . l e n g t h ,
c n t = 0 ;
$ i m g s . e a c h ( f u n c t i o n ( i ) {
v a r $ i m g = $ ( t h i s ) ;
$ ( ” ) . l o a d (
f u n c t i o n ( ) {
+ + c n t ;
i f ( c n t = = = t o t a l I m g s ) {
$ i m g s . s h o w ( ) ;
$ c o n t a i n e r . m o n t a g e ( {
m i n w : 1 2 0 ,
l i q u i d : f a l s e ,
a l t e r n a t e H e i g h t : t r u e ,
a l t e r n a t e H e i g h t R a n g e : {
m i n : 1 2 0 ,
m a x : 4 8 0
} ,
m a r g i n : ,
f i l l L a s t R o w : t r u e
} ) ;
}
} ) . a t t r ( ‘ s r c ’ , $ i m g . a t t r ( ‘ s r c ’ ) ) ;
} ) ;
} ) ;
} ) ;
I u s e d t h i s s c r i p t t o b u i l t a n e x t e n s i o n f o r j o o m l a 1 . 7 – 2 . 5 w i t h l i g h t b o x f u n c t i o n . T h a n k s t o a l l g u y s f r o m c o d r o p s f o r s o m a n y i n s p i r a t i o n .
S o r r y , t h e c o r r e c t l i n k i s :
h t t p : / / w w w . e x t e n s i o n s . w e b b e r r y - w e b d e s i g n . d e
I ’ m t r y i n g t o u s e t h i s s c r i p t h t t p : / / p o t o m a k . g i t h u b . c o m / j q u e r y - i n s t a g r a m / t o g e t p h o t o s f r o m i n s t a g r a m a n d u s e w i t h t h e m o n t a g e . I c a n g e t e i t h e r i n s t a g r a m o r t h e m o n t a g e t o w o r k b u t n o t b o t h t o g e t h e r . A n y h e l p ?
h o w d o i m a k e t h e i m a g e l o a d f a s t e r , c u z m i n e o n e t a k e a w h i l e
v a r $ c o n t a i n e r = $ ( ‘ # a m - c o n t a i n e r ’ ) ,
$ i m g s = $ c o n t a i n e r . f i n d ( ‘ i m g ’ ) . h i d e ( ) ,
t o t a l I m g s = $ i m g s . l e n g t h ,
c n t = 0 ;
I d e l e t e d t h e . h i d e ( ) , s o t h a t t h e i m a g e s d o n t h a v e w a i t t i l l a l l t h e i m a g e s a r e l o a d e d t o b e d i s p l a y , t h o u g h i t s a c r i f i c e s o m e b e a u t y o f t h e i m a g e g r i d b e f o r e a l l i m a g e s a r e d i s p l a y e d
a n y o n e h a v e a n y b e t t e r s o l u t i o n t o s p e e d u p t h e i m a g e d i s p l a y t i m e ?
T h i s i s b u g g y w i t h f i r e f o x a n d w i t h t h e c o n t a i n e r b e i n g a p e r c e n t a g e w i d t h . W o r k s f i n e a t 1 0 0 % a n d w i t h a d e f i n e d p x w i d t h b u t a s s o o n a s y o u t y p e i n a p e r c e n t a g e . I t f a i l s o n l o a d a n d w h e n y o u r e s i z e t h e w i n d o w . E v e n y o u r e x a m p l e 7 f a i l s s o m e t i m e s w h e n I r e s i z e t h e w i n d o w . H a v e a p l a y a r o u n d a n d y o u w i l l b e a b l e t o t r i g g e r i t s o n o t a l l t h e p i c t u r e s f i t o n t h e o n e r o w .
T h a n k y o u . Y o u s t a r t e d t o i m p l e m e n t a m o u s e o v e r z o o m f u n c t i o n . W o u l d b e g r e a t , i f w e c o u l d g e t t h a t t o w o r k .
C h e e r s ,
V i n c e n t
V e r y c o o l ! I ’ m m a k i n g a f e w m o d s t o t h e c o d e , t o s e t o p a c i t y t o t h e i m a g e s a d d t h i s t o r e s e t . c s s ;
f i e l d s e t , i m g {
o p a c i t y : . 6 ;
}
f i e l d s e t , i m g : h o v e r {
o p a c i t y : 1 . 0 ;
}
T o c h a n g e t h e b a c k g r o u n d c o l o r t o a d d b o r d e r s t o t h e i m a g e s , j u s t s e t m a r g i n = 1 i n t h e h t m l a n d e d i t d e m o . c s s ;
$ c o n t a i n e r . m o n t a g e ( {
f i l l L a s t R o w : t r u e ,
a l t e r n a t e H e i g h t : t r u e ,
a l t e r n a t e H e i g h t R a n g e : {
m i n : 9 0 ,
m a x : 2 4 0
} ,
m a r g i n : 1
} ) ;
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — -
b o d y {
b a c k g r o u n d : # 0 0 0 ;
c o l o r : # f f f ;
f o n t - f a m i l y : ‘ P T S a n s N a r r o w ’ , A r i a l , s a n s - s e r i f ;
f o n t - s i z e : 1 2 p x ;
}
L i g h t b o x i n t e g r a t i o n i s s i m p l e .
M e c o i s a d i s t r a c t i o n - f r e e s p a c e f o r r e a d i n g a n d d i s c o v e r i n g n e w s l e t t e r s , s e p a r a t e f r o m t h e i n b o x . T r y i t , u n c l u t t e r y o u r i n b o x .
E x p l o r e t h e s i t e
● H o m e
● A r t i c l e s
● T u t o r i a l s
● P l a y g r o u n d
● D e m o s
● C o l l e c t i v e
● C S S R e f e r e n c e
● F r e e b i e s
● A b o u t
● G e t i n t o u c h
● A d v e r t i s e
● P r i v a c y P o l i c y
● L i c e n s e
F o l l o w C o d r o p s
● X
● I n s t a g r a m
● T e l e g r a m
● M a s t o d o n
● F a c e b o o k
● G i t H u b
● R S S F e e d
● C o n t e n t d e l i v e r e d b y
● © C o d r o p s 2 0 2 4
S u p p o r t u s o n