Masonry.js not taking effect - javascript

I am simply testing the Masonry.js jQuery plugin/effect on my site, got barely anything on the site apart from the basics, even copied everything from a demo site and it still didn't work. Can't understand why.
It appears as the Masonry jQuery plugin is just not taking any effect or loading, but the page loads the file correctly and the code to call it to action is the Exact same as that on a demo site which it works fine on. As a test I've even got my stylesheet connecting directly from this example site, and all id's and class names are the same.
Live: http://bit.ly/1k7RgDS
Example Site (working fine for this site): http://bit.ly/1kcCmJA
Masonry jQuery Site: http://masonry.desandro.com/
HTML
<div id="container">
<div class="masonryImage">
<img src="http://lorempixum.com/200/200/food/1" alt="">
</div>
<div class="masonryImage">
<img src="http://lorempixum.com/200/150/food/10" alt="">
</div>
<div class="masonryImage">
<img src="http://lorempixum.com/200/250/food/3" alt="">
</div>
<div class="masonryImage">
<img src="http://lorempixum.com/200/200/food/1" alt="">
</div>
<div class="masonryImage">
<img src="http://lorempixum.com/200/150/food/10" alt="">
</div>
<div class="masonryImage">
<img src="http://lorempixum.com/200/250/food/3" alt="">
</div>
<div class="masonryImage">
<img src="http://lorempixum.com/200/200/food/1" alt="">
</div>
<div class="masonryImage">
<img src="http://lorempixum.com/200/150/food/10" alt="">
</div>
<div class="masonryImage">
<img src="http://lorempixum.com/200/250/food/3" alt="">
</div>
<div class="masonryImage">
<img src="http://lorempixum.com/200/200/food/1" alt="">
</div>
<div class="masonryImage">
<img src="http://lorempixum.com/200/150/food/10" alt="">
</div>
<div class="masonryImage">
<img src="http://lorempixum.com/200/250/food/3" alt="">
</div>
<div class="masonryImage">
<img src="http://lorempixum.com/200/200/food/1" alt="">
</div>
<div class="masonryImage">
<img src="http://lorempixum.com/200/150/food/10" alt="">
</div>
<div class="masonryImage">
<img src="http://lorempixum.com/200/250/food/3" alt="">
</div>
</div>
jQuery
<script src="//code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="<?php HTTP_HOST ?>/Scripts/masonry.pkgd.min.js"></script>
<script>
$(function(){
var $container = $('#container');
$container.imagesLoaded( function(){
$container.masonry({
itemSelector : '.masonryImage'
});
});
});
</script>

The example site is using a different version of the jQuery masonry plugin.
If you use the syntax provided on the masonry.js website it will work.
The correct syntax:
var $container = $('#container');
// initialize
$container.masonry({
itemSelector: '.masonryImage'
});

going to the page and opening firebug i see:
$container.imagesLoaded is not a function
imagesLoaded is not something native to jquery.. you probably need to add this jquery extension to your page

I'm guessing that you're using the latest version of Masonry. The site you referenced uses an older version of Masonry (v2), coming into version 3, Desandro removed imagesLoaded, so if you want to use imagesLoaded, you'll have to include the JS file from Desandro's page:
http://imagesloaded.desandro.com/
In which case your original code will work, however a better way to do it would be
var $container = $('#container');
$container.masonry({
itemSelector: '.masonryImage'
});
$container.imagesLoaded(function () {
$container.masonry();
});
This is probably overkill unless you plan on dynamically loading in new images / don't know the dimensions of your images as Masonry needs those to perform properly. If that's the case, I'd go with including it.

Related

How to open a new page with the same image showing as you clicked on using jquery

I am relatively new to javascript and I'm looking for the best possible way to explain this problem. Hope anyone can give me advice on this
I have this :
<div class="col-md-4">
<img src="">
<img src="">
<img src="">
</div>
When Clicked on img it's redirected to the stuffedd.html page. However this contains 2 columns with images. A vertical thumbnail column and a middle column with large image.
Like this:
<div class="middle containerscroll">
<img src="" id="Mdrie" class="img-responsive ">
<img src="" id="Mvier" class="img-responsive ">
<img src="" id="Mvijf" class="img-responsive ">
</div>
div class="col-md-9 hidden-xs hidden-sm">
<img src="" id="drie" class="img-responsive single">
<img src="" id="vier" class="img-responsive single">
<img src="" id="vijf" class="img-responsive single">
</div>
I got this far with Jquery :
$(document).ready(function(){
"use strict";
$( ".single" ).hide();
$( "#Mdrie" ).on('click',function() {
$('#drie').toggle();
$(".single").not('#drie').hide();
});
How do I make the stuffedd.html open with the image I clicked on in the second div (all the images with class .single)
Do I declare a variable which I fill in as:
$( "var" ).show();
website is: www.damondebacker.com if you need to see it.
If I understand the question, the second page needs to be aware of what you clicked on the previous page, consider adding some identifier into the URL that identifies the image:
<img src="">
Then the second page has a spot to extract it from. If you don't want it in the URL you could set a cookie or use the LocalStorage object.
Try to transfer the ID of the picture on the first page with your URL. So you click on the Image and the link is something like /stuffed.html?id=drie. Later on your stuffed site, you get the parameter with jquery in a variable and show exactly this image. Here is a short tutorial for URL Parameters and jQuery

flip thumbnail via button click

I found this sample and it looks good, so I put a thumbnail from bootstrap.
http://www.bootply.com/129165
And I like to implement it to the site my developing.
http://hotmeltcoatingmachines.com/
what I want is to flip the thumbnail thru button click.
How can I do that.
Thanks
<div class="flip">
<div class="card">
<div class="face front">
<div class="thumbnail">
<img src="..." alt="...">
<div class="caption">
<h3>front</h3>
<p>...</p>
<p>Flip Button</p>
</div>
</div>
</div>
<div class="face back">
<div class="thumbnail">
<img src="..." alt="...">
<div class="caption">
<h3>back</h3>
<p>...</p>
<p>Button flip</p>
</div>
</div>
</div>
</div>
</div>
</div>
sample code
http://www.bootply.com/pZXSuyPPWx
The answer by #menaka will flip all the icons. If you want to flip only the icon that was clicked then use something like below:
$('.fliper-btn').click(function(e){
$(e.target).closest('.flip').find('.card').toggleClass('flipped');
});
Make sure you keep the custom class fliper-btn as suggested by #menaka.
Flip
change JQuery code like this
$('.fliper-btn').click(function(){
$('.flip').find('.card').toggleClass('flipped');
});
and give flip action buttons a custom class name like 'fliper-btn' and add it like this
Flip

swiper.js multiple imgs per slide lazy loading not working

thanks for reading, I try to use swiper.js and it works fine with the lazy loading demo, but in the demo, there is only one image per slide, but I want to represent 4 imgs per slide, which turns out only the first img in each slide will show up.
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<!-- Required swiper-lazy class and image source specified in data-src attribute -->
<img data-src="1.jpg" class="swiper-lazy">
<img data-src="2.jpg" class="swiper-lazy">
<img data-src="3.jpg" class="swiper-lazy">
<img data-src="4.jpg" class="swiper-lazy">
<img data-src="5.jpg" class="swiper-lazy">
<!-- Preloader image -->
<div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div>
</div>
<div class="swiper-slide">
<img data-src="2.jpg" class="swiper-lazy">
<div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div>
</div>
<div class="swiper-slide">
<img data-src="3.jpg" class="swiper-lazy">
<div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div>
</div>
<div class="swiper-slide">
<img data-src="4.jpg" class="swiper-lazy">
<div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div>
</div>
</div>
</div>
so, I am trying to read the jquery code in swiper.js, and due to my ability, I can not figure it out, tbh, I can not understand.
any help?
I got it.
As long as I am using the same src with the ones in the slides after, it was lazy loaded too. After replacing all the data-srcs with diff ones, it works.
Thank, swiper.js

Javascript: Mouseover thumbnail to view large image - Multiple instances

I'm looking for a javascript option that will allow me to mouseover a thumbnail image to replace the "large" image. The trick here is using the anchor href from the thumbnail link as the large image source. I need this to work for multiple instances.
The <img src="large1.jpg"> etc. can be removed if that helps
Below is a simplified version of the HTML code I am using. This code cannot be changed.
Every id and class can be unique.
<div class="image-1">
<img src="large1.jpg">
</div>
<div id="thumbs">
<a id="thumb_1" href="large1.jpg" title="1"><img src="small1.jpg" alt="image 1"/></a>
<a id="thumb_2" href="large2.jpg" title="2"><img src="small2.jpg" alt="image 1"/></a>
<a id="thumb_3" href="large3.jpg" title="3"><img src="small3.jpg" alt="image 1"/></a>
</div>
...
<div class="image-2">
<img src="large2.jpg">
</div>
<div id="thumbs">
<a id="thumb_1" href="another_large1.jpg" title="1"><img src="anout_small1.jpg" alt="image 1"/></a>
<a id="thumb_2" href="another_large2.jpg" title="2"><img src="another_small2.jpg" alt="image 1"/></a>
<a id="thumb_3" href="another_large3.jpg" title="3"><img src="another_small3.jpg" alt="image 1"/></a>
</div>
...
check this solution
http://jsfiddle.net/dtdaynjp/
add to all "large" image unique class, image-1, image-2, image-3..
for each thumbs link add class similar like appropriate large image: thumb-image-1, thumb-image-2, thumb-image-1...
add this jQuery code:
$(function() {
$(".mouseover a").mouseover(function(){
var src=$(this).attr('href');
var classs=$(this).attr('class');
classs=classs.substr(6);
$('.'+classs).find('img').attr('src',src);
})
})
I would just use the CSS :hover selector. Then you can add animations and other cool things to your images.
EXAMPLE HERE.

Show next and previous image in Twitter Bootstrap Carousel

I’m searching for a way to display the next and previous slideshow image within the Twitter Bootstrap Carousel.
As per default it just show the current image and if I remove the display:none css property it has every item in the carousel below each other. I’ve tried to play with the CSS but haven’t got it to work.
The idea is to display the current slideshow image in the middle and then the next and previous image with opacity, not necessarily clickable.
I’ve tried different slideshows and carousels but can’t seem to find anyone which satisfies these requirements and some of those who come close will not adapt to the responsive design that Bootstrap provides.
Normally when I’m using the carousel with multiple items, I just group e.g. images within the <div class="item"> div like:
<div class="item active">
<img src="http://www.entiri.com/minett/img/slider/1.jpg" alt="">
<img src="http://www.entiri.com/minett/img/slider/2.jpg" alt="" style="">
<img src="http://www.entiri.com/minett/img/slider/3.jpg" alt="" style="">
</div>
<div class="item">
<img src="http://www.entiri.com/minett/img/slider/1.jpg" alt="">
<img src="http://www.entiri.com/minett/img/slider/2.jpg" alt="" style="">
<img src="http://www.entiri.com/minett/img/slider/3.jpg" alt="" style="">
</div>
<div class="item">
<img src="http://www.entiri.com/minett/img/slider/1.jpg" alt="">
<img src="http://www.entiri.com/minett/img/slider/2.jpg" alt="" style="">
<img src="http://www.entiri.com/minett/img/slider/3.jpg" alt="" style="">
</div>
But this will not do what I want because it rotates all three items at the time and not take one image each.
Any suggestion, advice, or link for some walk-through or tutorial will be very much appreciated.
Cheers
This is the link that helped me
Twitter Bootstrap 101: The Carousel

Categories

Resources