Responsive full width carousel with carouFredSel.js - responsive-design

I am currently using carouFredSel.js to serve up a full width carousel on my site. I chose this plugin because of its full width capabilities with the ability to partially show the previous and next images on the left and right edges of the screen.
I am also using Bootstrap 3, but was unsuccessful achieving the same behavior, so that's why I chose to go with a plugin.
The problem I am experiencing is making the carousel responsive. The plugin has an option to make it responsive by adding 'responsive: true' to the options, but when I do that, it breaks the layout.
My code with placeholder images can be found at http://jsfiddle.net/vUCZ8/. I would recommend looking at the full screen result at http://jsfiddle.net/vUCZ8/embedded/result/
#intro {
width: 580px;
margin: 0 auto;
}
.wrapper {
background-color: white;
width: 480px;
margin: 40px auto;
padding: 50px;
box-shadow: 0 0 5px #999;
}
#carousel img {
display: block;
float: left;
}
.main-content ul {
margin: 0;
padding: 0;
list-style: none;
display: block;
}
.main-content li {
display: block;
float: left;
}
.main-content li img {
margin: 0 20px 0 20px;
}
.list_carousel.responsive {
width: auto;
margin-left: 0;
}
.clearfix {
float: none;
clear: both;
}
.prev {
float: left;
margin-left: 10px;
}
.next {
float: right;
margin-right: 10px;
}
.pager {
float: left;
width: 300px;
text-align: center;
}
.pager a {
margin: 0 5px;
text-decoration: none;
}
.pager a.selected {
text-decoration: underline;
}
.timer {
background-color: #999;
height: 6px;
width: 0px;
}
$(function() {
$('#carousel').carouFredSel({
width: '100%',
items: {
visible: 3,
start: -1
},
scroll: {
items: 1,
duration: 1000,
timeoutDuration: 3000
},
prev: '#prev',
next: '#next',
pagination: {
container: '#pager',
deviation: 1
}
});
});
<div class="main-content">
<ul id="carousel">
<li><img src="http://coolcarousels.frebsite.nl/c/2/img/building6.jpg" /></li>
<li><img src="http://coolcarousels.frebsite.nl/c/2/img/building6.jpg" /></li>
<li><img src="http://coolcarousels.frebsite.nl/c/2/img/building6.jpg" /></li>
<li><img src="http://coolcarousels.frebsite.nl/c/2/img/building6.jpg" /></li>
</ul>
<div class="clearfix"></div>
</div>

This is the correct way to implement responsive with this plugin:
responsive: true // you must add this
As you can see it is not breaking and working perfectly. http://jsfiddle.net/3mypa/
This is with the STANDARD template.
I believe you are searching for a different template, isn't this what you are looking for?
http://coolcarousels.frebsite.nl/c/44/coolcarousel.html

I've been looking at this issue as well and the best I've found is to watch for a window size and react accordingly. For example
$(window).resize(function(){
//listens for window resize
var TimeOutFunction;
clearTimeout(TimeOutFunction);
//To try and make sure this only fires after the window has stopped moving
TimeOutFunction=setTimeout(function(){
$('.slides').trigger("destroy",true);
//Destroys the current carousel along with all it's settings - extreme but It wouldn't accept setting changes once running
if($(window).width()<1170){
//The width should be the width of a single image since I assume your using the same image size for all images on the slider.
$(function(){
$('#carousel').find('.slides').carouFredSel({
width:'100%',
items:{
visible:1,
start:-1
},
responsive:true,
minimum:3
})
})
}else{
$(function(){
$('#carousel').find('.slides').carouFredSel({
width:'100%',
items:{
visible:3,
start:-1
},
responsive:false,
minimum:3
})
})
}
},500)
})
This way once the window size is below the width of the images and the responsive action should kick in it does but once it's larger than one image again it moves back to the truncated view.
Admittedly it could tidied up more for portabilities sake but you that should give you the right basis to work on.

Related

How to add animation on container changing its width realtime

I am making a form that expands when the user enters any character/key and gets back to its original width when there is no character left, for the plus point, I want to add animation to that expandable form so it gives a smooth look.
Here is the code and I want this action as follows
Not in React but I made an example in Vanilla JS hope it helps. I used CSS variables for changing width and making it smooth.
Instead of removing svg icons completely try scaling it down to 0 or changing it opacity to 0
const btns = Array.from(document.querySelectorAll('.btn'))
const input = document.querySelector('input')
btns.shift() // for leaving first button
input.addEventListener('input', (event) => {
btns.forEach((btn) => {
if (event.target.value.trim().length > 0) {
btn.classList.add('scale-0')
btn.parentElement.classList.add('width-50')
} else {
btn.classList.remove('scale-0')
if (btn.parentElement.classList.contains('width-50')) {
btn.parentElement.classList.remove('width-50')
}
}
})
})
#import 'https://cdn.jsdelivr.net/gh/KunalTanwar/normalize/css/normalize.inter.min.css';
body {
display: grid;
place-items: center;
}
.row {
--column-gap: 1rem; /* 8px */
width: 100%;
display: flex;
max-width: 525px;
column-gap: var(--column-gap);
}
.row input {
flex-grow: 1;
border-radius: 100vmax;
padding: 0.75rem 1.25rem;
border: 1px solid #c1c1c1;
}
.container {
--column-gap: 0.5rem; /* 16px */
--btn-size: 3.125rem; /* 50px */
flex-shrink: 0;
display: inherit;
column-gap: var(--column-gap);
width: calc(var(--column-gap) * 3 + var(--btn-size) * 4);
transition: width 250ms ease;
}
.container.width-50 {
width: var(--btn-size);
}
.container .btn {
width: var(--btn-size);
border-radius: 50%;
aspect-ratio: 1/1;
border: 1px solid #c1c1c1;
transition: transform 250ms ease;
}
.container .btn.scale-0 {
transform: scale(0);
}
<div class="row">
<div class="container">
<button class="btn">1</button>
<button class="btn">2</button>
<button class="btn">3</button>
<button class="btn">4</button>
</div>
<input type="text" />
</div>

Animating movement of other items in ng-repeat with ngAnimate

Sorry for the vague title, but I couldn't find a fitting short description.
So, I have a list of different items which I'm using ng-repeat to show. Some of them might be removed or added to that list.
I'm using ng-enter etc to animate the transition of the items entering and exiting the view. The problem is, the rest of the items, the ones that are not being added or removed, look like they hop and skip around instead of flowing naturally when items between them are being removed or added.
I made a codepen:
If you click any of the players, you remove them. Click reset to bring them back in. If you remove any of the players in the middle, you can see they jump to the left instantly after the removed item is done with its animation. I would like it to slide over to it's new position instead.
http://codepen.io/utrolig/pen/oxQVVZ
HTML:
<div ng-app="test">
<div ng-controller="AnimateController as vm">
<div class="player" ng-repeat="player in vm.items" ng-click="vm.toggleActiveState(player)" ng-if="player.active">
<div class="imgcont">
<img ng-src="{{player.img}}" />
<div class="jerseyno">
<span>#{{::player.jerseyNumber}}</span>
</div>
</div>
<div class="playername">
<span ng-bind="::player.name"></span>
</div>
</div>
<div class="resetbutton" ng-click="vm.resetActiveState(vm.players)">
<span>Reset</span>
</div>
</div>
</div>
JS:
(function(){
'use strict';
angular
.module('test', ['ngAnimate'])
.controller('AnimateController', AnimateController);
function AnimateController(){
var vm = this;
vm.toggleActiveState = toggleActiveState;
vm.resetActiveState = resetActiveState;
vm.items = [
{
name: "Pavel Bure",
active: true,
team: "Vancouver Canucks",
jerseyNumber: 10,
img: "https://nhl.bamcontent.com/images/headshots/current/168x168/8455738.jpg"
},{
name: "Wayne Gretzky",
jerseyNumber: 99,
active: true,
team: "Vancouver Canucks",
img: "https://nhl.bamcontent.com/images/headshots/current/168x168/8447400.jpg"
},{
name: "Jaromir Jagr",
jerseyNumber: 68,
active: true,
team: "Florida Panthers",
img: "https://nhl.bamcontent.com/images/headshots/current/168x168/8448208.jpg"
},{
name: "Mats Zuccarello",
jerseyNumber: 36,
active: true,
team: "New York Rangers",
img:"https://nhl.bamcontent.com/images/headshots/current/168x168/8475692.jpg"
}
];
//////////////
function toggleActiveState(item){
item.active = item.active ? false : true;
}
function resetActiveState(arr){
for (var i = 0; i < vm.items.length; i++){
vm.items[i].active = true;
}
}
}
})();
CSS:
body, html {
min-height: 100vh;
position: relative;
font-family: 'Arial', sans-serif;
background: #1d1f20;
color: rgba(255,255,255,0.7)
}
.imgcont {
border-radius: 8px;
}
.imgcont img {
border-radius: 8px;
}
.jerseyno {
position: absolute;
top: 6px;
right: 6px;
padding: 4px;
background: rgba(0,0,0,.75);
border-radius: 4px;
}
.resetbutton {
display: block;
float: left;
border-radius: 4px;
margin: 24px;
padding: 24px;
background: rgba(0,0,0,.5);
cursor: pointer;
}
.playername {
position: absolute;
bottom: 6px;
left: 6px;
background: rgba(0,0,0,.75);
padding: 4px;
border-radius: 4px;
}
.player {
float: left;
margin-right: 12px;
position: relative;
cursor: hand;
cursor: pointer;
transition: .5s all;
}
.player.ng-enter {
opacity: 0;
transform: translateY(-50%);
}
.player.ng-enter-active {
opacity: 1;
transform: translateY(0%);
}
.player.ng-leave-active {
opacity: 0;
transform: translateY(-50%);
}
Thanks!

Re-order containers using media queries

I'm wanting to re-order a number of containers when the webpage is being viewed on a particular device.
I currently have three divs floated left. Two smaller divs either side of a larger div. However, when the media query kicks in a would like the middle of the three to sit above the other two. In theory changing its position from 2nd to 1st.
Is this possible with pure CSS? Or would I need to get jQuery involved? I've set up a test fiddle here for anybody who can help with my initial attempts, but I'm having no joy so far... http://jsfiddle.net/r8qZ2/
Example HTML:
<div class="panels">
<div class="panel-one">Panel 1</div>
<div class="panel-two">Panel 2</div>
<div class="panel-three">Panel 3 </div>
</div>
Example CSS:
.panels {
width: 100%;
max-width: 1280px;
margin: 0 auto;
}
.panel-one, .panel-three {
width: 24.0625%;
height: 400px;
float: left;
background: red;
}
.panel-three {
margin: 0 0 0 1.25%;
}
.panel-two {
width: 49.375%;
height: 400px;
float: left;
margin: 0 0 0 1.25%;
background: blue;
}
#media only screen and (max-width: 800px) {
.panel-one, .panel-three {
width: 49%;
height: 400px;
}
.panel-three {
margin: 0 0 0 2%;
}
.panel-two {
width: 100%;
float: none;
clear: left;
margin: 0;
}
}
Any help would be gratefully received!
Re-order responsive containers with CSS? With float based layouts, no. In cases with just one floated sidebar it's possible, but not with two.
If you adjust your layout not to use floats then it's most certainly possible.
Note: I highly recommend a mobile first-approach to your CSS, using min-width media queries. However since you're using max-width in your example I will also do so in mine:
Using position: absolute:
Place the element you want to be at the top as the first element in your HTML markup, and position the sidebars to the sides with position: absolute. Give the parent element position: relative, and give it a padding value equal to the width of the sidebars.
Then, with media queries, remove the padding and position: absolute you set.
Example:
HTML:
<div class="panels">
<div class="panel-two">Panel 2</div>
<div class="panel-one">Panel 1</div>
<div class="panel-three">Panel 3</div>
</div>
CSS:
.panels {
position: relative;
padding: 0 25%;
}
.panel-one,
.panel-three {
position: absolute;
top: 0;
bottom: 0;
width: 25%;
}
.panel-one { left: 0; }
.panel-three { right: 0; }
#media only screen and (max-width: 800px) {
.panels {
padding: 0;
}
.panel-one,
.panel-three {
position: static;
width: auto;
}
}
Here's a pen with your markup adjusted to this.
A major drawback to this is that the sidebars are taken out of the content flow with position: absolute, so depending on your layout this may not be a possible solution.

Left hand side and right hand side listboxes with add one, add all, remove one, remove all buttons in the middle

I have a left-hand side (lhs) list box and right-hand side (rhs) list box I want to be able to select items in the lhs listbox and add one or all of them to the rhs listbox. Then I'd also like a remove one or all from the rhs returning them to the lhs. How would I accomplish this? So far, I can only manage getting the index value of the lhs box to the right but it won't take the actual item name for some reason. This is the code that does that:
private void SelectOne_Click(object sender, RoutedEventArgs e)
{
listBoxFin.ItemsSource = listBoxStart.SelectedIndex.ToString();
}
Hi this is not the final solution but this will help you lot.
Working DEMO.
HTML
<div class="wrapper">
<div class="selectbox alignleft">
<ul id="selection" class="cf">
<li>One <span class="desc">Description</span></li>
<li>...</li>
<li>...</li>
</ul>
</div>
<div class="movebutton alignleft">
<input class="button mover" value=">>" type="button" />
</div>
<div id="moving" class="movebox alignleft">
<ul class="cf">
<li>One <span class="desc">Description</span>
</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
</div>
<div class="alignleft">
<input class="button" id="move-up" type="button" value="Up" />
<input class="button" id="move-down" type="button" value="Down" />
</div>
CSS
.cf:before, .cf:after {
content:"";
display: table;
}
.cf:after {
clear: both;
}
/* For IE 6/7 (trigger hasLayout) */
.cf {
zoom: 1;
}
/* general purpose classes */
.nodisplay {
display: none;
}
.nodisplay_strict {
display: none !important;
}
.alignleft {
float: left;
}
.alignright {
float: right;
}
.button {
cursor: pointer;
background: #eee;
border: 0;
min-width: 116px;
padding: 5px 0;
margin-bottom: 2px;
display: block;
}
body {
padding: 25px;
font-family:Verdana, Geneva, sans-serif;
font-size: 12px;
}
li {
display: block;
cursor: pointer;
padding: 5px;
font-weight: bold;
position: relative;
border-bottom: 1px solid #fff;
}
li.active {
background: #000;
color: #fff;
}
.wrapper {
width: 960px;
margin: 0 auto;
}
.selectbox {
border: 1px solid;
width: 150px;
min-height: 199px;
max-height: 199px;
overflow-y: auto;
position: relative;
}
.movebox {
border: 1px solid;
width: 200px;
min-height: 199px;
max-height: 199px;
overflow-y: auto;
position:relative;
margin-left: 10px;
margin-right: 10px;
}
span.desc {
display: block;
padding-top: 5px;
color: #7a7a7a;
font-weight: normal;
font-style: italic;
}
li.active span.desc {
color: #ccc;
}
.movebox .delete, .movebox .unmoved {
display: inline-block;
position: absolute;
right: 5px;
top: 5px;
z-index: 999;
background:url(icon-close.png) no-repeat 0 0 red;
width: 10px;
height: 10px;
text-indent: -99999px;
}
.movebutton {
margin-left: 10px;
}
.movebutton .mover {
background: url(icon_right.png) no-repeat 0 0 #eee;
height: 48px;
margin: 65px auto 0;
min-width: 0;
text-align: center;
width: 48px;
}
.moved {
background: #d9fffe;
}
#move-up {
background: url("icon_up.png") no-repeat 0 0 #eee;
height: 48px;
margin: 0px auto 0;
min-width: 0;
text-align: center;
width: 48px;
}
#move-down {
background: url("icon_down.png") no-repeat 0 0 #eee;
height: 48px;
margin: 15px auto 0;
min-width: 0;
text-align: center;
width: 48px;
}
JavaScript
// JavaScript Document
$(document).ready(function (e) {
$('.selectbox li, .movebox li').click(function () {
$(this).addClass('active').siblings().removeClass('active');
});
$('.mover').click(function () {
$('.selectbox li.active').addClass('moved').prependTo('.movebox ul').prepend('<span class="delete alignright" onclick="moveToLHS(this);">DELETE</span>');
});
$('.mover').click(function () {
$('.selectbox li.active').addClass('moved');
$('.movebox li.active').removeClass('active');
setTimeout(function () {
$('.movebox li').removeClass('moved');
}, 1500);
});
$('.movebox ul li').each(function () {
$(this).prepend('<span class="unmoved alignright" onclick="deleteFromRHS(this);">DELETE</span>');
});
$("#move-up").click(moveUp);
$("#move-down").click(moveDown);
$("#reset-list").click(resetList);
});
//DELETE
function moveToLHS(t) {
$(t).parent().remove().prependTo('.selectbox ul');
$('.selectbox li').click(function () {
$(this).addClass('active').siblings().removeClass('active');
});
//deleting span
$('.selectbox ul li .delete').each(function () {
$(this).remove();
});
}
function deleteFromRHS(d) {
$(d).parent().remove();
}
// LI Up Down
function moveUp() {
$("#moving li.active").each(function () {
var listItem = $(this);
var listItemPosition = $("#moving li").index(listItem) + 1;
if (listItemPosition == 1) return false;
listItem.insertBefore(listItem.prev());
});
}
function moveDown() {
var itemsCount = $("#moving li").length;
$($("#moving li.active").get().reverse()).each(function () {
var listItem = $(this);
var listItemPosition = $("#moving li").index(listItem) + 1;
if (listItemPosition == itemsCount) return false;
listItem.insertAfter(listItem.next());
});
}
function resetList() {
$("#moving").html(originalItems);
}
Working DEMO
As H.B. noted, there are many ways this could be accomplished. Probably the most widely acclaimed architecture for WPF is MVVM, so I'll try to outline a solution with respect to my understanding of that architecture.
The ViewModel will expose a few different properties: LHSList, LHSSelectedItem, RHSList, RHSSelectedItem (collections are ObservableCollections here) as well as a few commands - MoveLHSSelectedToRHS, MoveLHSToRHS, MoveRHSSelectedToRHS, MoveRHSToLHS.
The lists are simple bindings to the ListViews in the View, and the SelectedItem's of those ListViews are also bound accordingly. The commands simply operate on the lists and the selected items. For example, MoveLHSSelectedToRHS would be a command with an action something like:
public void OnMoveLHSSelectedToRHS()
{
if(LHSSelectedItem==null)
return;
RHSList.Add(LHSSelectedItem);
LHSList.Remove(LHSSelectedItem);
LHSSelectedItem=null;
}
Unfortunately, it looks like you are using code behind at the moment. If you are not familiar with MVVM, I'd suggest looking into Josh Smith's WPF articles - they're a great place to start!

Float: Right IE7 Bug

I can't figure out IE7 float right bug! This is killing me. My NAV bar looks great everywhere except IE7. I already created a specific IE7 CSS and have tried various approaches, but still no success.
link text
It appears the LI elements are floating outside the #NAV inside the .container.
Anyone of a IE7 fix for FLOAT:RIGHT?
Many thanks.
Here is my code:
.container {
width: 983px;
margin: 0 auto;
background: fuchsia;
}
ul#nav {
height: 44px;
margin: 32px auto;
position: relative;
}
ul#nav li, ul#nav li a {
display: block;
height: 44px;
margin-left: 3px;
position: relative;
}
ul#nav li {
padding-left: 0;
height: 44px;
position: relative;
z-index: 10060;
}
<div class="container">
<ul id="nav">
<li><a class="navtop_7" href="#"></a></li>
<li><a class="navtop_6" href="#"></a></li>
<li><a class="navtop_5" href="#"></a></li>
<li><a class="navtop_4" href="#"></a></li>
<li><a class="navtop_3" href="#"></a></li>
<li><a class="navtop_2" href="#"></a></li>
<li><a class="navtop_1" href="#"></a></li>
</ul>
</div>
This jsfiddle.net example displays in IE7 the way I think you want it to, based on your description. (For future reference, supply a reference image you are trying to achieve.)
.container {
width: 983px;
margin: 0 auto;
background: fuchsia;
}
ul#nav {
height: 44px;
margin: 32px auto;
}
ul#nav li {
display: block;
float: right;
background: green;
padding-left: 0;
width: 140px
height: 44px;
}
ul#nav li a {
background: blue;
display: block;
height: 44px;
width: 137px;
margin-left: 3px;
}

Resources