Using JQuery.BlackAndWhite with a Cycle2 Carousel? - jquery-cycle2

I am putting together a Cycle2-based carousel where, essentially, every other image should be a black and white image. So, on first load it would be something like this:
IMAGE A = B&W
IMAGE B = Color
IMAGE C = B&W
IMAGE D = NOT SHOWN
Once the slideshow advances, it would be something like this:
IMAGE A = NOT SHOWN
IMAGE B = B&W
IMAGE C = Color
IMAGE D = B&W
I discovered Gianluca Guarini's jQuery.BlackAndWhite plugin which handles the black and white conversion by adding the class .bwWrapper. If I use the scrollHorz parameter, the two work nicely together, but not when using carousel. The carousel runs as expected, but BlackAndWhite isn't coming into play.
My code is below. The only difference between the two blocks is one is in a DIV. My guess is jQuery.BlackAndWhite runs on (window).load and Cycle2 carousel enters the picture after that?
Any thoughts on how to get these to cooperate?
<h3>Cycle2</h3>
<div id="slideshow">
<img src="/assets/images/img01.jpg" height="200" alt="test image">
<img src="/assets/images/img02.jpg" height="200" alt="test image">
<img src="/assets/images/img03.jpg" height="200" alt="test image">
<img src="/assets/images/img04.jpg" height="200" alt="test image">
<img src="/assets/images/img05.jpg" height="200" alt="test image">
</div>
<div class="center">
Prev
Next
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="/assets/js/jquery.cycle2.js"></script>
<script src="/assets/js/jquery.cycle2.carousel.min.js"></script>
<script src="/assets/js/jquery.BlackAndWhite.js"></script>
<script>
$(window).load(function() {
$('#slideshow').cycle({
fx: 'carousel',
speed: '1000',
slides: '> a',
next: '#next',
prev: '#prev'
});
$('.bwWrapper').BlackAndWhite({
hoverEffect: false,
invertHoverEffect: false
});
});
</script>

You can just use CSS to make the images grayscale. Here is a cross-browser compatible style that I've used in the past. The first filter is for Firefox, second for IE, and third for the other modern browsers.
.bwWrapper img{
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale");
filter: gray; /* IE6-9 */
-webkit-filter: grayscale(1); /* Google Chrome, Safari 6+ & Opera 15+ */
}

Related

v-card-media with base64 image

I am creating a captcha image in ColdFusion and returning it as a REST feed with Taffy. It is then shown in Vuetify
ColdFusion / Taffy code
<cfscript>
component extends="taffy.core.resource" taffy_uri="/captcha" {
function get() hint="Sends one out" {
var captcha = CreateUUID().right(4) & DayOfWeekAsString(DayOfWeek(now())).left(1).lcase() & "!";
// This is ColdFusion
var tempFile = "ram:///#captcha#.txt";
var myImage = ImageCreateCaptcha(100, 300, captcha, "low");
ImageWriteBase64(myImage, tempFile, "png", true, true);
var myfile = FileRead(tempFile);
FileDelete(tempFile);
return rep({'status' : 'success', 'time' : GetHttpTimeString(now()),
'captcha_hash' : hash(captcha), 'captcha_image' : myFile
});
}
...
</cfscript>
It returns something like this:
{"status":"success","captcha_image":"data:image/png;base64,iVBORw0KG /d67W8EALALKJQAABBYAAAILABAYAEAILAAdr...
Vue
I can display the image via
<img :src="captcha_image" height="100px;">
Vuetify
If I don't use a height, the image does not come out at all
If I use a height like this, it comes out with the wrong aspect ratio.
<v-card-media :src="captcha_image" height="100px"></v-card-media>
Is there a work around? Or is <v-card-media the wrong tool for this?
The reason is that v-card-media use the image as a background image of a div with fixed height.
If you want to keep the aspect ratio. You can use <img /> tag with a width="100%" instead.
<img src="data:image/jpeg;base64,/9j/4AAQ..." width="100%">
demo: https://codepen.io/jacobgoh101/pen/bMrBWx?&editors=101
<div id="app">
<v-app id="inspire">
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-card>
<img src="data:image/jpeg;base64,/9j/4AAQ..." width="100%">
<v-card-title primary-title>
...
</v-card-title>
<v-card-actions>
...
</v-card-actions>
</v-card>
</v-flex>
</v-layout>
</v-app>
</div>

rearrange order of div columns according to device tablet or phone. zurb foundation 4

I am using zurb foundation 4 framework. The following test site looks fine on desktop view for me. On desktop view, I have on the left side: large-7 columns (gray content text box); on the right side: i have: large-5 columns (image 1 green and image 2 blue). Please help me with exact code example. On tablet and phone view, I would like to rearrange the order of the div columns to: image 1 green box first, and then below that is gray content text box, and then below that is image 2 blue box. Please help me with exact code example. Thank you so much in advance!
Here is the preview of what I have so far: http://www.endsnore.com/_test1/marketing5.html
Here is an example of what I want to happen on tablet and phone view: http://www.endsnore.com/_test1/images/_delete14.jpg
You can't have that layout without doing some jquery or javascript. There is no built-in css solution or even javascript from Foundation that will do the trick for you.
You can try this solution. First you need to have a layout something like this:
<div class="row">
<div class="small-12 columns show-for-small" id="topContent"></div>
<div class="large-7 small-12 columns panel">1st column</div>
<div class="large-5 small-12 columns panel">
<div id="img1" class="panel">img1</div>
<div id="img2" class="panel">img2</div>
</div>
</div>
And then have this script to move the first image on top:
$(document).foundation();
$(function () {
var wd = $(window).width();
if (wd < 768) {
$("#topContent").append($("#img1").detach());
}
});
Take note that the script only works on load of the page and not when resizing the browser - I don't think you will need it that way anyway. But for whatever reason you do, then just enclose the "width" logic in a resize function, something like:
$(window).resize(function () {
var wd = $(window).width();
if (wd < 768) {
$("#topContent").append($("#img1").detach());
}
});

How to use jquery cycle 2 continuous slider but more than one image?

I am using jquery cycle 2 to get a continuous slideshow effect...http://jquery.malsup.com/cycle2/demo/continuous.php
Here is code:
<div class="cycle-slideshow cycle-autoinit"
data-cycle-fx="scrollHorz"
data-cycle-slides="> div"
data-cycle-speed="3000"
data-cycle-pause-on-hover="true"
data-cycle-timeout="1"
data-cycle-easing="linear"
data-cycle-carousel-visible=5>
<div>
<a href="#slide.Link" target="_blank">
<img src="#Url.Content("~/content/cms/slideshow/")#slide.ImageName" alt="" /></a>
</div>
<div>
<a href="#slide.Link" target="_blank">
<img src="#Url.Content("~/content/cms/slideshow/")#slide.ImageName" alt="" /></a>
</div>
</div>
This works. However only one image slides across the screen and then the next appears. What i want is all images slides across next to each other so like 5 are appearing and going round on a rotation?
Hi I think you have to set your data-cycle-fx=carousel.
Try this:
<div class="cycle-slideshow cycle-autoinit"
data-cycle-fx="carousel"
data-cycle-slides="> div"
data-cycle-speed="3000"
data-cycle-pause-on-hover="true"
data-cycle-timeout="1"
data-cycle-easing="linear"
data-cycle-carousel-visible=5>
...
I can't test it now but I hope it works.
Cycle2's carousel transition plugin must be included in order to use the carousel effect.
Here is an example of what you want if it helps: http://jsfiddle.net/CersX/2/
I basically added data-cycle-carousel-fluid=true data-cycle-easing="linear" to there example.
Just swap out the images for yours.
I based my code from http://codepen.io/colir/pen/bhcAx
Here's the answer -
carousel-slide-dimension on Jquery Cycle2 -fixed width/height
'carouselSlideDimension' as your argument or:
data-cycle-carousel-slide-dimension=ANUMBER
$this.cycle({
"allowWrap" : false,
"carouselSlideDimension" : "151px",
"carouselVisible" : 3,
"fx" : "carousel",
"log" : false,
"timeout" : 0,
"next" : "#" + id + " .next",
"prev" : "#" + id + " .prev",
"slideActiveClass" : "active",
"slides" : "> .slide",
});

How do I resize the canvas in Raphael.js?

I'm having difficulty resizing the canvas in Raphael.js. I thought I could simply use:
var paper = Raphael("paper", 100, 100);
and this would create a canvas using the ID "paper" with a width and height of 100 pixels. However when I try this the canvas doesn't initialize with these settings. I'm using some of the free icons on the Raphael.js website and I was wondering how I would change the size of the icons? Do I have to use the transform function as well? If so could somebody please create a jsfiddle example.
Thanks in advance.
Sorry if I haven't explained myself very well, but Raphael.js is completely new to me.
EDIT:
I tried your suggestions, but to no avail. Here's the code I'm working on. Maybe I have a conflict or something. Any ideas?
<!DOCTYPE html>
<html>
<head>
<title>Logo Experiment</title>
<link rel="stylesheet" href="css/960_16_col.css"/>
<link rel="stylesheet" href="css/stylesheet.css"/>
<script src="js/jquery.min.js"></script>
<script src="js/raphael-min.js"></script>
<script src="js/script.js"></script>
</head>
<body>
<div class="container_16">
<div class="grid_4">
<div id="design"></div>
</div>
<div class="grid_2">
<div class="arrow"></div>
</div>
<div class="grid_4">
<div id="build"></div>
</div>
<div class="grid_2">
<div class="arrow"></div>
</div>
<div class="grid_4">
<div id="deliver"></div>
</div>
<div class="clear"></div>
</div>
</body>
</html>
window.onload = function() {
var design = Raphael("design");
design.path("M24.359,18.424l-2.326,1.215c0.708,1.174,1.384,2.281,1.844,3.033l2.043-1.066C25.538,20.822,24.966,19.652,24.359,18.424zM19.143,14.688c0.445,0.84,1.342,2.367,2.274,3.926l2.414-1.261c-0.872-1.769-1.72-3.458-2.087-4.122c-0.896-1.621-1.982-3.108-3.454-5.417c-1.673-2.625-3.462-5.492-4.052-4.947c-1.194,0.384,1.237,4.094,1.876,5.715C16.73,10.147,17.991,12.512,19.143,14.688zM26.457,22.673l-1.961,1.022l1.982,4.598c0,0,0.811,0.684,1.92,0.213c1.104-0.469,0.81-1.706,0.81-1.706L26.457,22.673zM24.35,15.711c0.168,0.339,2.924,5.93,2.924,5.93h1.983v-5.93H24.35zM18.34,15.704h-4.726l-3.424,5.935h11.66C21.559,21.159,18.771,16.479,18.34,15.704zM3.231,21.613l3.437-5.902H2.083v5.93h1.133L3.231,21.613zM15.048,10.145c0-0.93-0.754-1.685-1.685-1.685c-0.661,0-1.231,0.381-1.507,0.936l2.976,1.572C14.97,10.725,15.048,10.444,15.048,10.145zM14.343,12.06l-3.188-1.684L9.62,13.012l3.197,1.689L14.343,12.06zM3.192,26.886l-0.384,1.108v0.299l0.298-0.128l0.725-0.896l2.997-2.354l-3.137-1.651L3.192,26.886zM9.02,14.044l-4.757,8.17l3.23,1.706l4.728-8.186L9.02,14.044z").attr({fill: "#666", stroke: "#000"});
var build = Raphael("build");
build.path("M28.537,9.859c-0.473-0.259-1.127-0.252-1.609-0.523c-0.943-0.534-1.186-1.316-1.226-2.475c-2.059-2.215-5.138-4.176-9.424-4.114c-1.162,0.017-2.256-0.035-3.158,0.435c-0.258,0.354-0.004,0.516,0.288,0.599c-0.29,0.138-0.692,0.147-0.626,0.697c2.72-0.383,7.475,0.624,7.116,2.966c-0.08,0.521-0.735,1.076-1.179,1.563c-1.263,1.382-2.599,2.45-3.761,3.667l0.336,0.336c0.742-0.521,1.446-0.785,2.104-0.785c0.707,0,1.121,0.297,1.276,0.433c0.575-0.618,1.166-1.244,1.839-1.853c0.488-0.444,1.047-1.099,1.566-1.178l0.949-0.101c1.156,0.047,1.937,0.29,2.471,1.232c0.27,0.481,0.262,1.139,0.521,1.613c0.175,0.324,0.937,1.218,1.316,1.228c0.294,0.009,0.603-0.199,0.899-0.49l1.033-1.034c0.291-0.294,0.501-0.6,0.492-0.896C29.754,10.801,28.861,10.035,28.537,9.859zM13.021,15.353l-0.741-0.741c-3.139,2.643-6.52,5.738-9.531,8.589c-0.473,0.443-1.452,1.021-1.506,1.539c-0.083,0.781,0.95,1.465,1.506,2c0.556,0.533,1.212,1.602,1.994,1.51c0.509-0.043,1.095-1.029,1.544-1.502c2.255-2.374,4.664-4.976,6.883-7.509c-0.312-0.371-0.498-0.596-0.498-0.596C12.535,18.451,11.779,17.272,13.021,15.353zM20.64,15.643c-0.366-0.318-1.466,0.143-1.777-0.122c-0.311-0.266,0.171-1.259-0.061-1.455c-0.482-0.406-0.77-0.646-0.77-0.646s-0.862-0.829-2.812,0.928L7.44,6.569C7.045,6.173,7.203,4.746,7.203,4.746L3.517,2.646L2.623,3.541l2.1,3.686c0,0,1.428-0.158,1.824,0.237l7.792,7.793c-1.548,1.831-0.895,2.752-0.895,2.752s0.238,0.288,0.646,0.771c0.196,0.23,1.188-0.249,1.455,0.061c0.264,0.312-0.196,1.41,0.12,1.777c2.666,3.064,6.926,7.736,8.125,7.736c0.892,0,2.021-0.724,2.948-1.64c0.925-0.917,1.639-2.055,1.639-2.947C28.377,22.567,23.704,18.309,20.64,15.643z").attr({fill: "#666", stroke: "#000"});
var deliver = Raphael("deliver");
deliver.path("M17.078,22.004l-1.758-4.129l-2.007,4.752l-7.519-3.289l0.174,3.905l9.437,4.374l10.909-5.365l-0.149-4.989L17.078,22.004zM29.454,6.619L18.521,3.383l-3.006,2.671l-3.091-2.359L1.546,8.199l3.795,3.048l-3.433,5.302l10.879,4.757l2.53-5.998l2.257,5.308l11.393-5.942l-3.105-4.709L29.454,6.619zM15.277,14.579l-9.059-3.83l9.275-4.101l9.608,3.255L15.277,14.579z").attr({fill: "#666", stroke: "#000"});
$('.arrow').each(function(i) {
arrow = Raphael($(this)[0]);
arrow.path("M10.129,22.186 16.316,15.999 10.129,9.812 13.665,6.276 23.389,15.999 13.665,25.725z").attr({fill: "#666", stroke: "#000"});
});
};
#design {
width: 100px;
height: 100px;
}
To answer your exact question in the title, you would use paper.setSize(width, height)
From the Raphael docs:
Your other questions have different answers.
var paper = Raphael("paper", 100, 100); requires that you have some DOM element with the id="paper" already on your page. That DOM element should have width and height enough to hold your canvas (in this case, 100x100). Or, you can leave off the width and the height and it will take on the width and height of the container (very convenient). You can also produce a canvas without a DOM element by putting in all four dimensions, such as var paper = Raphael(0, 0, 100, 100); to make a 100x100 canvas at the top left of the document.
To resize the Raphael icons, you can use the transform function. For example icon.transform("s2"); to make it twice as large.
This fiddle shows how to create a Raphael canvas and put the pencil icon on it, make it yellow, and double-sized. Note that we need to scale around the top left corner (normally it scales around the center) to prevent it from clipping off the top and left of the page.
var pencil = "M25.31,2.872l-3.384-2.127c-0.854-0.536-1.979-0.278-2.517,0.576l-1.334,2.123l6.474,4.066l1.335-2.122C26.42,4.533,26.164,3.407,25.31,2.872zM6.555,21.786l6.474,4.066L23.581,9.054l-6.477-4.067L6.555,21.786zM5.566,26.952l-0.143,3.819l3.379-1.787l3.14-1.658l-6.246-3.925L5.566,26.952z"
var paper = Raphael(0,0,200,200);
var icon = paper.path(pencil).attr({fill: "yellow"}).transform("s2,2,0,0");

Child div to 100% when parent's height is dynamical | HTML/CSS

I want the image to be centered next to the text.The amount of text will be different in each box so I can't set the height.As I research people mainly use two ways of vertical centering.Using line-height which I can't use, because I don't have fixed height.Second one is using absolute positioning which I can't use, because left div with image inside will cover the text.If I set padding to text, when image is not there it won't look good.
The best I could think of is to use jQuery to get and set the container height, and then set the margin according to the height.
<div class="container">
<div class="image_holder">
<img src="http://blog.oxforddictionaries.com/wpcms/wp-content/uploads/cat-160x160.jpg" alt="cat" />
</div>
<p>text</p>
</div>
<style type="text/css">
.container {
width:600px;
overflow:hidden; }
.image_holder {
width:100px;
height:100%;
float:left;
background:#eaf0ff; }
p {
width:500px;
float:left; }
</style>
<script>
$('.container').css('height', $('.container').height() );
$('.image_holder').css('margin-top', ( $('.container').height() - $('.image_holder img').height() ) / 2 );
</script>
Is there a way to do it cleanly with pure CSS ?
The best solution I came up with is to absolutely position the picture inside the box and then use javascript to remove padding if there is no image in the box.