Giter Site home page Giter Site logo

jquery.diamonds.js's Introduction

diamonds.js

Tired of straight grids where everything is vertically and horizontally aligned? Why not tilt everything by 45 degrees? This jQuery plugin lets you easily do just that!

Features

  • Auto resizes
  • No images, all css
  • AMD aware plugin
  • Test coverage!

Demo

See the demo page or checkout /demo/demo.html in this repo.

Usage

Add this to your <head>

<link rel="stylesheet" type="text/css" href="diamonds.css" />

Add this right before your closing </body>

<script type="text/javascript" src="jquery.diamonds.js"></script>

Note: The path may change depending on where you put the css file.

html

<div class="diamondswrap">
    <a href="#" class="item">Hello world</a>
    <a href="#" class="item">Hello</a>
    <a href="#" class="item">Hello</a>
    ... many more items!
</div>

js

$(".diamondswrap").diamonds({
    size: 250, // Size of the squares
    gap: 1 // Pixels between squares
});

Options

size

Size of diamonds in pixels. Both width and height. Only squares allowed.

gap

Pixels between each square. The size of the squares will be reduced by this gap.

itemSelector

The css selector to use to select diamonds-items.
Default: .item

hideIncompleteRow

Hide last row if there are not enough items to fill it completely.
Default: false

autoRedraw

Auto redraw diamonds when it detects resizing.
Default: true

Methods

Intialize

$(".diamondswrap").diamonds({
    size: 250, // Size of the squares
    gap: 1 // Pixels between squares
});

Note: Calling any other method before diamonds has been initialized will cause an error to be thrown.

draw

Manually trigger a redraw.

$(".diamondswrap").diamonds("draw");

setOptions

Change options after initialize

$(".diamondswrap").diamonds("setOptions", {
    hideIncompleteRow: true
});

Note: Changing options will trigger a redraw since size, gap, or hideIncompleteRow might have changed..

destroy

Destroy diamonds and return everything to how it was.

$(".diamondswrap").diamonds("destroy");

Events

All events are prefixed with diamonds:. Which means that this is how you listen to a diamonds event:

$(...).on("diamonds:beforeDraw", function() { ... })

Some events are also called with arguments. One such event is beforeSetOptions. This is how you catch the arguments.

$(...).on("diamonds:beforeSetOptions", function(event, newOptions) {
	newOptions.gap = 10; // Always set the gap to 10
});

Some events can also abort the method by calling .preventDefault, for example if you want to prevent all drawing.

$(...).on("diamonds:beforeDraw", function(event) {
	event.preventDefault(); // Stops the draw method
});

As a rule of thumb, all events starting with before or on can abort the method.

Events Arguments Can abort method
beforeInit yes
afterInit no
beforeStopAutoRedraw yes
afterStopAutoRedraw no
beforeStartAutoRedraw yes
onAutoResize { before: ... , current: ... } yes
afterStartAutoRedraw no
beforeSetOptions new options yes
afterSetOptions new options no
beforeDraw yes
afterDraw no
beforeDestroy yes
afterDestroy no

jquery.diamonds.js's People

Contributors

mqchen avatar no1lov3sme avatar

Stargazers

Thanos Kostoulas avatar Smith avatar  avatar  avatar Yottaline avatar aneesh.mb avatar Higor Christian avatar Mominul Islam avatar Cynthia Vanoirbeek avatar Nazmul Haque shimul avatar Meily Chhon avatar Joseph Corrales avatar Faridul Hassan avatar Ali Torki avatar Aoshi Fujioka avatar zhangbg avatar Jay avatar Joohun, Maeng avatar Alice1017 avatar Shun Yamaguchi avatar enki avatar Lee Han Bin avatar Natanael Maldonado avatar Владимир Морин avatar Sasha-Shae W. avatar Laurie.S avatar  avatar Peter Janak avatar Veronica avatar Chelsea Adams avatar yoclove avatar Zoran Perin avatar  avatar Gaus Surahman avatar A.J. Wohlfert avatar Henry Bi avatar Sebastian Serna avatar Kenta Murakami avatar  avatar Arifur Rahman avatar Hasan Hafiz Pasha avatar  avatar Geosynchron avatar ZJ Huang avatar Melissa avatar  avatar Pavel Monahov avatar amitabha ghosh avatar Bradley Bain avatar Jeff Harris avatar Michael Anthony avatar Jon Ang avatar  avatar Dipesh KC avatar  avatar Weronika Rudnicka avatar Przemysław "Pirax" Czumaj avatar  avatar Giulia Santoiemma avatar Simone avatar  avatar Raheel Khan avatar katsuhide avatar Eko Prastyo avatar Nemanja Avramović avatar  avatar Marc Cometa avatar Dermot McGuire avatar Devin Walker avatar Cole Reid avatar Pablo avatar Satoshi Homura avatar  avatar  avatar  avatar VOIDNIL avatar pepperstreet avatar Jonathan Barratt avatar  avatar Abdul Rauf avatar tim geaney avatar Pierre JdlF avatar  avatar 没眉毛的青蛙 avatar Onyx avatar  avatar Antonio Caputo avatar Josh Carr avatar Tolga Ergin avatar Berkant Fidan avatar Edo avatar foo9 avatar Álvaro González G. avatar KennethPCF avatar xqsapper avatar Kenta Suzuki avatar KiKiKi-KiKi avatar Bong Anceno avatar Felo Odriozola avatar  avatar

Watchers

 avatar Brad avatar Hsuching avatar KiKiKi-KiKi avatar Michael Anthony avatar Stephan Lück avatar Thierry avatar  avatar 没眉毛的青蛙 avatar null avatar  avatar Nikola Kostov avatar chiakialala  avatar Zach Walker avatar Mindy avatar

jquery.diamonds.js's Issues

Math

In the css, line 24 regarding .diamond-row-lower .diamond-box : the commented formula seems wrong :
I'll use 1 - 1 / sqrt(2) / 2 instead of 0.5 + 1 / sqrt(2) / 2

Not Responsive

Hi

It is making a distorted layout as it doesn't get sorted properly on viewport of 300px. can you please resolve it

row-lower absolute position overlaps content below

Hello.

I'm reworking the site I used this for originally and would like to see if you can help with a problem I've been having. When I have both row-upper & row-lower populated with diamonds, row-lower overlaps the content below it on the page (because of it's absolute position?), see screenshot.

Because it's responsive I can't simply add a margin/padding to the last row-lower because that row is always in the code so when I don't need the padding (when there is no content in the last row-lower) it will add it too.

Perhaps something can be added to the script that figures out if row-lower has content or not and removes it if it is empty?

Thanks

screen shot 2016-09-04 at 11 45 30

help :)

Hello
I read very carefully your readme.md fail and i do the same thing, but nothing happens. Very sorry, i'm new in this! Can you help me?
Thank you!

screen shot 2014-01-20 at 9 33 25 pm

Roll over

Hello,

First of all thank you for your work. It's great.
Also, i try to make a roll over but i can't. Maybe you can help me.
I want to have a picture in the diamond and in a roll over want to have a backgound color with some text in the center (it can be an an image).
How can i make it ?

This is my entry

<img src="<?php bloginfo('template_directory'); ?>/library/images/diamonds/branding.jpg" class="item">

Thank you very much and sorry for my english.

Chrome 33.0.1750.117 m bug

Broken on Chrome version 33.0.1750.117 m.
Looks a bit better, by setting:

.diamond-row-upper, .diamond-row-lower {
    width: 101%;
}

but still does not fixes.

Change images?

I'd like to use this gallery but I only want 4 diamonds in the arrangement shown below. Is this possible?

Also, how do I change the images so it doesn't display your flickr account? I'd prefer to have it link to images on my personal server or desktop and not on flickr.

Thanks in advance for your guidance.
screen shot 2014-12-29 at 6 12 43 pm

IE9 Fails on console.debug

Just wanted to leave a note that your plugin seems to fail in IE9 when debug is enabled. Disabled it works fine. This can be seen on the demo page. If fails on Console.debug call.

Doesn't work on IE8

On Internet Explorer 8 diamond js doen't work. Also javasciprt is broken all over the page.
Error:
Object doesn't support this property or method. Line: 1 Char: 1

Different sizes

Hello

Could there be a way of allowing different sized diamonds within the same call/wrapper div? When I make a second call using the same wrapper but different itemSelectors the first call is ignored and the items don't show.

Thanks

Images are cutted

Hello,

Before of all let me say that this is the best gallery plugin ever seen.
On http://wpuploadimage.com/?p=147 i've tried this jquery plugin but it cut me images: as can you see images are cutted in the lower part.

Is it my problem?

Thanks
P.S: As you can see i'm using it on wordpress

Changing flickr feed with my own images

Hi Guys,

I'm kinda new with jquery and script, but I've managed to successfully added this jquery to wordpress. But now, I need to change the flickr image feed with my own images.

I figured out that this gather the images and build the structure.

$.getJSON("https://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",
{
format: "json",
tagmode: "any",
tags: "abstract"
}).done(function(data) {
var wrap = $("#flickrItems");
$.each(data.items, function(index, item) {
$("").attr("href", item.link).addClass("item").css("background-image", "url(" + item.media.m + ")").appendTo(wrap);
});
}).always(function() {
initDiamonds($("#diamondsControls"), $("#flickrItems"));
initControls($("#diamondsControls"), $("#flickrItems"));
});

What would be the best way to gather specific image for each diamond? Where should I begin and how should I proceed?

Thanks

Layout issue

Hi Moquan,

This is Boon, I contacted you on twitter about your plugin. Once again thanks for making the plugin, it's really cool. I'm using it to build my portfolio site and it's been super helpful. Everything was working fine until yesterday when Chrome just crapped out. I'm not sure if Google made some changes to Chrome.

Something odd is happening with the way the diamonds are wrapping. It seems like the div containing them is too small and its causing the diamond row to break prematurely and create scroll bars for the overflow. This only happens with chrome. Firefox, IE, and Safari are fine. I checked your plugin demo and the same thing is happening there so I don't think it's something I did. If you can provide any kind of help it would greatly be appreciated. I was so close to finishing my site! :( I've provided a screenshot of what's happening and the link to my site as well. Thanks so much for your response! You can also email at [email protected]

www.boon.dudlyboys.com

screen shot 2014-02-22 at 9 49 05 am

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.