I'm using Masonry and imageLoaded to load a wall of images : everytime an image is loaded, masonry layout is refreshed.
This works as intended, but problem is that most of the time, Masonry will move already loaded items to another position on refresh. Is there a way to force Masonry to keep already arranged items where they are ?
All the image have the same width (but not the same height).
HTML (with Bootstrap) :
<div class="container-fluid">
<div id="gallery">
<div class="item col-sm-3">
<img src="1.jpg" alt="">
</div>
<div class="item col-sm-3">
<img src="2.jpg" alt="">
</div>
<div class="item col-sm-3">
<img src="3.jpg" alt="">
</div>
<!--more items -->
</div>
</div>
JS :
// hide images
$('.item img').hide();
//init Masonry
var $grid = $('#gallery').masonry({
itemSelector: '.item',
transitionDuration: 0,
percentPosition: true,
});
// fade in and layout Masonry after each image loads
imagesLoaded(".item img").on( 'progress', function( instance, image ) {
$(image.img).fadeIn();
$grid.masonry('layout');
});
I have the same issue (fixed width, different height and I want fixed items) and I resolve with the following code:
//Here I attach the new loaded items (html var) in the #container div.
$("#gallery").append(html).each(function(){
$('#gallery').masonry('reloadItems');
});
$('#gallery').imagesLoaded(function(){
$('#gallery').masonry();
});
If you want to see it working and the effect, you could visit http://pintevent.com to see if is the same desired behavior. Hope it helps!
Related
I am new to react-slick
initially before i added more components to the react-slick, it was sliding seamlessly
but after adding in more code in the slider, (something which i think is not the problem) react-slick now slides for some time, and then stops, when refreshed, again it slides, and stops, i have totally failed to understand where the issue could be, below is a sample code
import "./App.css";
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";
import Slider from "react-slick";
function App() {
const settings = {
customPaging: function(i) {
return(
<p>{i + 1}</p>
)
},
dots: true,
infinite: true,
speed: 1000,
slidesToShow: 1,
slidesToScroll: 1,
adaptiveHeight: true,
// focusOnSelect: true,
// lazyLoad: true,
// swipeToSlide: false
// fade: true,
centerMode: true
// slidesPerRow: 2,
// rows: 2,
// arrows: false,
// draggable: false
};
return (
<Slider {...settings}>
<div className="box">
<h3>1 how to make div slider in html and css </h3>
<h3>1 how to make div slider in html and css </h3>
<h3>1 how to make div slider in html and css </h3>
</div>
<div className="box">
<h3>2 how to make div slider in html and css </h3>
</div>
<div className="box">
<h3>3 how to make div slider in html and css </h3>
<h3>1 how to make div slider in html and css </h3>
<h3>1 how to make div slider in html and css </h3>
<h3>1 how to make div slider in html and css </h3>
<h3>1 how to make div slider in html and css </h3>
</div>
<div className="box">
<h3>4 how to make div slider in html and css </h3>
</div>
<div className="box">
<h3>1 how to make div slider in html and css </h3>
<h3>5 how to make div slider in html and css </h3>
</div>
<div className="box">
<h3>6 how to make div slider in html and css </h3>
</div>
</Slider>
);
}
export default App;
I have this navbar that I would like to close already in lg or xl size and not in md size. I would like to understand how with alpine js:
<div>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine#v2.x.x/dist/alpine.min.js" defer></script>
<div x-data="{ sidebarOpen: false }" class="flex h-screen bg-gray-200">
<div :class="sidebarOpen ? 'block' : 'hidden'" #click="sidebarOpen = false" class="fixed z-20 inset-0 bg-black opacity-50 transition-opacity lg:hidden"></div>
<div :class="sidebarOpen ? 'translate-x-0 ease-out' : '-translate-x-full ease-in'" class="fixed z-30 inset-y-0 left-0 w-64 transition duration-300 transform bg-gray-900 overflow-y-auto lg:translate-x-0 lg:static lg:inset-0">
I did not understand how to close this sidebar already in xl size with alpine js and tailwind
Below is the link for the entire code:
https://tailwindcomponents.com/component/dashboard-template
i didn't quite understand how to use sidebar Open
From my understanding, you are trying to make the sidebar open and close. You can create the div for the sidebar and the div for the button that will be used to toggle.
You can use x-show="sidebarOpen = true" on the div that you want to show up when the sidebar is enabled.
Doing #click="sidebarOpen !sidebarOpen" will toggle the inverse state. So you can click the same button to show the sidebar, and close it.
<div x-data="{ sidebarOpen: false }" class="flex h-screen bg-gray-200">
{{-- This is sidebar button --}}
<div #click="sidebarOpen !sidebarOpen" class=" fixed z-20 inset-0 bg-black opacity-50 transition-opacity"></div>
{{-- This Is Sidebar Content --}}
<div x-show="sidebarOpen = true" class="fixed z-30 inset-y-0 left-0 w-64 transition duration-300 transform bg-gray-900 overflow-y-auto lg:translate-x-0 lg:static lg:inset-0">
</div>
</div>
I'm trying to align four pictures with their captions in a square grid.
I'm using the following HTML code:
<div class="grid">
<div class="post-block">
<img src="img1.jpg" />
<div class="caption">caption1</div>
</div>
<div class="post-block">
<img src="img2.jpg" />
<div class="caption">caption2</div>
</div>
<div class="post-block">
<img src="img3.jpg" />
<div class="caption">caption3</div>
</div>
<div class="post-block">
<img src="img4.jpg" />
<div class="caption">caption4</div>
</div>
</div>
and the following CSS code:
.post-block {
display: inline-block;
position: relative;
text-align: center;
}
If images and captions are the same size everything is ok, but when they are different I get this (an example):
I've tried to align images and captions of different sizes using CSS with no success. I need something like this:
Any help would be appreciated.
Thanks in advance
You'll need to use separate block elements at the same DOM level for the image and the caption to achieve what you've shown in the "RIGHT" image. Right now your caption DIV is nested inside the image DIV, and that's gonna do what you've shown. The caption DIV needs to be outside the image DIV.
You will probably want two separate div wrappers around each 2 photos..
Then align images vertically to bottom.
Vertical align images to bottom
<div class="myWrapClass">
<img src="my image">
<img src="my image">
</div>
<div class="myWrapClass">
<img src="my image">
<img src="my image">
</div>
then set the styling via inline or your css file
<div style="vertical-align:bottom;">
or
.myWrapClass{
vertical-align:bottom;
}
check out this site... Use the css properties there to keep it responsive
Example
I have :
<div id="container" class="masonry js-masonry">
<div class="item">
<img width="128" alt="image.jpg" class="image" src="small/thumb_Jennifer_Aniston-wallpaper.jpg">
</div>
<div class="item">
<img width="128" alt="image.jpg" class="image" src="small/thumb_Jennifer_Aniston-wallpaper.jpg">
</div>
</div>
and:
<script src="js/masonry.pkgd.min.js"></script>
<script src="js/imagesloaded.pkgd.min.js"></script>
<script type="text/javascript">
var container = document.querySelector('#container');
var msnry;
// initialize Masonry after all images have loaded
imagesLoaded( container, function() {
msnry = new Masonry( container );
});
</script>
Masonry work as axpected but images overlap.after I rezise the browser they show in the right way.
What is wrong? How shoud I do it?
How can I make a layout shown in this image
I could have done it easily with grid system but I want the first post's description off the grid system or below the both column. However, for mobile devices I want it to appear with the image or in the same grid like the image below
I don't expect you can do this with Bootstrap's CSS only cause the order of your elements change from desktop to mobile.
Try this html:
<div class="container">
<div class="row">
<div class="col-md-6 col-xs-12" style="background-color:red;">1</div>
<div class="rightblock col-md-6 col-xs-12">
<div class="row">
<div class="col-xs-12" style="background-color:lightgreen;">3</div>
<div class="col-xs-12" style="background-color:lightyellow;">4</div>
</div>
</div>
<div class="clearfix visible-md visible-lg"></div>
<div class="col-md-12 col-xs-12 lefttext" style="background-color:lightblue;">2</div>
</div>
</div>
Where 2 = the caption of your first item (1) and 3 and 4 are your second and third item.
For the mobile version use javascript to swap 2 (.lefttext) and the 3/4 block (.rightblock):
$(window).resize(function () {
if ($(window).width() < 992) {
$(".rightblock").insertAfter($(".lefttext"));
}
});
Demo: http://bootply.com/94560
Note 1: $(window).resize only will called on a real resize (from big to small) and not when opening the small screen direct. See here for better solution to react on screen size changes: How to detect responsive breakpoints of Twitter Bootstrap 3 using JavaScript?
Note 2: see http://getbootstrap.com/css/#grid-responsive-resets for explanation of the clearfix