React-slick not sliding attimes - react-slick

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;

Related

navbar tailwind does not disappear at xl

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>

Aurelia: templating. Include a template in another

I would like to use two layouts for my Aurelia app.
Home - FAQ - Login page don't contain a sidebar;
But everything else do contain this sidebar.
My architecture, with a sidebar is pretty complicated in HTML and is like:
div.container
div.sidebar
div.sidebar_content
div.site_content
So i can't just enable or disable the sidebar because it contains the view.
I have to make two pages like "app.html", defined in main.js, but how tell to Aurelia "Choose app.html for this page, and app2.html for this other page"?
I have found the setRoot function but i have bugs with it (the routes does not work properly when i change setroot)
Thank you for your answers
The router supports the concept of "layouts." This is documented here: http://aurelia.io/hub.html#/doc/article/aurelia/router/latest/router-configuration/10
Basically, you specify a layout for each route (you can specify a default layout on the router-view custom element:
app.html
<router-view layout-view="./layout-with-sidebar.html"></router-view>
app.js
export class App {
configureRouter(config, router) {
config.title = 'Aurelia';
var model = {
id: 1
};
config.map([
{ route: ['home', ''], name: 'home', title: "Home", moduleId: 'home', nav: true },
{ route: 'no-sidebar', name: 'no-sidebar', title: "No Sidebar", moduleId: 'no-sidebar', nav: true, layoutView: 'layout-without-sidebar.html' }
]);
this.router = router;
}
}
layout-with-sidebar.html
<template>
<div class="container">
<div class="row">
<div class="col-sm-2">
<slot name="sidebar"></slot>
</div>
<div class="col-sm-10">
<slot name="main-content"></slot>
</div>
</div>
</div>
</template>
layout-without-sidebar.html
<template>
<div class="container">
<div class="row">
<div class="col-sm-12">
<slot name="main-content"></slot>
</div>
</div>
</div>
</template>
home.html
<template>
<div slot="sidebar">
<p>I'm content that will show up on the right.</p>
</div>
<div slot="main-content">
<p>I'm content that will show up on the left.</p>
</div>
</template>
no-sidebar.html
<template>
<div slot="main-content">
<p>Look ma! No sidebar!</p>
</div>
</template>

Masonry / imagesLoaded : prevent layout refresh from moving already loaded items

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!

Loading svg images responsively in a bootstrap panel

I have a panel into which I want to embed an SVG image. On clicking on the panel body I want to open a modal window displaying the svg image full screen.
What ever the size of the SVG image be, I want it to fit - by compression or stretch - in both panel and the modal window, which would be full screen.
Here is the html
<div class="panel-body" data-toggle="modal" data-target="#myModal">
<embed src="test.svg" id="testsvg" type="image/svg+xml"/>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Some Name</h4>
</div>
<div class="modal-body">
<div class="svg-container">
<embed src="test.svg" id="testsvg" type="image/svg+xml"/>
</div>
</div>
</div>
</div>
</div>
I got help from this library
Here is an example
<div class="panel-body" id="SVGPanel">
<embed src="1.svg" id="testsvg" name="testsvg" type="image/svg+xml"/><!--</object>-->
</div>
And the java script
function elastic(newsvgPanelWidth)
{
var windowwidth = newsvgPanelWidth;//$(window).width();
var windowheight = $(window).height();
var imageheight;
var imagewidth;
var svgfile=document.getElementById("testsvg");
var SvgDoc;
SvgDoc=svgfile.getSVGDocument();
if(SvgDoc==null)
{
SvgDoc=svgfile.contentDocument;
}
alert("SVG contentDocument Loaded!"+SvgDoc);
var allSvgElements = SvgDoc.getElementsByTagName('svg');
for(var i = 0; i < allSvgElements.length; i++)
{
var element = allSvgElements[i];
alert(element);
if(element.getAttribute("width")!=null)
{
imagewidth=element.getAttribute("width");
}
if(element.getAttribute("height")!=null)
{
imageheight=element.getAttribute("height");
}
}
$("#SVGPanel").width(windowwidth);
$("#SVGPanel").height(windowheight);
var $section = $('#SVGPanel');
var $elem =$section.find('#testsvg');
var $panzoom = $elem.panzoom(
{
startTransform: 'scale(1.0)',
maxScale: 100,
increment: 0.5,
contain: true
}).panzoom('zoom', true);
var offsetwidth =1+ ((windowwidth-imagewidth)/imagewidth);
var offsetheight = 1+((windowheight-imageheight)/imageheight);
var twidth = imagewidth*((offsetwidth-1)/2);
var theight = imageheight*((offsetheight-1)/2);
$elem.panzoom("setMatrix", [ offsetwidth, 0, 0,offsetheight, twidth,theight ]);
//$elem.panzoom("setMatrix", [1, 0, 0, 1, 0,0 ]);
$elem.panzoom('option', 'contain', false);
}
What I did was I took the screen width and Height and found the difference and thus the percentage to width and height of the actual SVG file to be increased and used the library to set those params.
With little bit more tweak and math the svg image would perfectly fit the parent component.

How to dynamically change view in angularjs using ui-router

I have a named view called myView in which I have two div elements that I want to show conditionally using ng-show based on whether the value of $scope.states['currentState'] is 'A' or 'B'. The value of $scope.states['currentState'] is changed when an anchor tag is clicked which calls the doStuff function on the myController controller.
The issue I am having is when the anchor tag is clicked and the doStuff function is clicked, it shows on the console that the value of $scope.states['currentState'] has been modified, but its not updating the myView named view accordingly.
Following is the code for app.js, myView.html and index.html files. The index.html file is being used as a <div ui-view></div> in an index.ejs file that I am rendering using Express with Node.js.
app.js
var app = angular.module("app", ['ui.router']).
config(['$stateProvider', '$urlRouterProvider', '$locationProvider', function($stateProvider, $urlRouterProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$urlRouterProvider.otherwise('/');
$stateProvider
.state('home', {
url: '/',
views: {
'': { templateUrl: 'partials/index.html' },
'myView#home': {
templateUrl: 'partials/myView.html',
controller: 'myController'
},
'myOtherView#home': {
templateUrl: 'partials/myOtherView.html',
controller: 'myController'
}
}
});
}])
app.controller("myController", ['$scope', function($scope){
var states = ['A', 'B'];
$scope.states = states;
$scope.states['currentState'] = states['currentState'] || 'A';
$scope.doStuff = function(toState) {
//doing stuff
$scope.states['currentState'] = toState;
console.log($scope.states['currentState']);
};
} ]);
index.html
<div class="main">
<div class="container">
<div class="row margin-bottom-40">
<div class="col-md-12 col-sm-12">
<div class="content-page">
<div class="row">
<div ui-view="myView"></div>
<div ui-view="myOtherView"></div>
</div>
</div>
</div>
</div>
</div>
</div>
myView.html
<div ng-controller='myController'>
<div ng-show="states['currentState'] == 'A'">
//displaying this div if the currentState is A
<a ng-click="doStuff('B')">Do stuff and show B</a>
</div>
<div ng-show="states['currentState'] == 'B'">
//displaying this div if the currentState is B
</div>
</div>
Could somebody help me understand that why am not getting the div with states['currentState'] == 'B' shown, even when I see the value of console.log($scope.states['currentState']) changed from 'A' to 'B' when the doStuff function is called in myController?
Edit:
Here is the demo of the issue I am facing.
Okay So I was mistaken in my comment.
The real issue was that you used {{}} in your ng-show which is not needed as these expect to take angular expressions.Also I would make current state a property of your scope as at the moment you are trying to make it a property of an array inside your scope.
Hope that helps! Below is the modified code for your view:
<div ng-controller='MainCtrl'>
<div ng-show="currentState === 'A'">
<a ng-click="doStuff('B')">Do stuff and show B</a>
</div>
<div ng-show="currentState === 'B'">
<a ng-click="doStuff('A')">Do stuff and show A</a>
</div>
</div>
EDIT: Working plunker http://plnkr.co/edit/1llQMQEdxIwu65MNoorx?p=preview

Resources