hide and show features using jquery - arrays

I need some help. I'm designing a website. In home page, there are several links. With the help of jquery, I want to hide and show content (on the same page) depending on the links which the user clicks.
I have achieved it, but I feel; its not the right approach. Is there anyway to achieve this with minimal code? may be using arrays or loops? Please have a look at the example that I have created.
Thanks in advance.
$('.para2').hide();
$('.para3').hide();
<!--One-->
$('.one').click(function(){
$('.para1').show();
$('.para2').hide();
$('.para3').hide();
})
<!--Two-->
$('.two').click(function(){
$('.para2').show();
$('.para1').hide();
$('.para3').hide();
})
<!--three-->
$('.three').click(function(){
$('.para3').show();
$('.para1').hide();
$('.para2').hide();
})
<ul>
<li><a href="#" class="one" >Para -1</a></li>
<li><a href="#" class="two" >Para -2</a></li>
<li><a href="#" class="three" >Para -3</a></li>
</ul>
<div class="para1" style="width:500px; padding:10px; border:1px solid red; background:#009966">
<h1>Para -1</h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi auctor purus at massa venenatis nec facilisis lectus volutpat. Suspendisse potenti. Proin facilisis, nisl a auctor venenatis, metus nisi congue tortor, quis laoreet nisl magna in massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </div>
<div class="para2" style="width:500px; padding:10px; border:1px solid red; background:#333333">
<h1>Para -2</h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi auctor purus at massa venenatis nec facilisis lectus volutpat. Suspendisse potenti. Proin facilisis, nisl a auctor venenatis, metus nisi congue tortor, quis laoreet nisl magna in massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </div>
<div class="para3" style="width:500px; padding:10px; border:1px solid red;">
<h1>Para -3</h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi auctor purus at massa venenatis nec facilisis lectus volutpat. Suspendisse potenti. Proin facilisis, nisl a auctor venenatis, metus nisi congue tortor, quis laoreet nisl magna in massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </div>

You may change like below:
Html:
<ul>
<li><a href="#" class="paraLink" data-para="one" >Para -1</a></li>
<li><a href="#" class="paraLink" data-para="two" >Para -2</a></li>
<li><a href="#" class="paraLink" data-para="three" >Para -3</a></li>
</ul>
<div class="para one" ...
<div class="para two" ...
<div class="para three" ...
JS:
$(function() {
$('.paraLink').click(function(e) {
e.preventDefault();
$('.para').hide();
$('.'+$(this).data('para')).show();
});
});
THE WORKING DEMO.

Related

how to convert component to pdf using jspdf and htm2canvas

i am trying to build cv maker web application.and i need to convert componet to pdf file.
here my code
const handelDownload = () => {
html2canvas(componentRef.current).then(function (canvas) {
const divImage = canvas.toDataURL("image/png");
const pdf = new jsPDF();
pdf.addImage(divImage, "PNG", 0, 0);
pdf.save("download.pdf");
});
};
return (
<>
<h1>hello world</h1>
<div ref={componentRef}>
<h1 className="text-4xl bg-red-500">My Component</h1>
<p className="text-lg">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel
ipsum et velit posuere tempus sed ac ex. Vestibulum ante ipsum primis
in faucibus orci luctus et ultrices posuere cubilia curae; Integer
eget augue faucibus, placerat leo vitae, dignissim mi. Fusce id nibh
id risus congue consequat ac ut libero. Duis ut tincidunt turpis. Nam
scelerisque tortor in risus interdum consequat. Ut vel lectus sem.
Nulla hendrerit erat vel massa finibus, eget laoreet tellus ultrices.
Integer rhoncus lectus quis libero imperdiet, et viverra turpis
fermentum. Donec ullamcorper nisl eget felis dictum, at suscipit dolor
viverra. Etiam ullamcorper sem sit amet ante bibendum iaculis.
</p>
</div>
</>
problem is qulity of pdf is wrost and elements are not in the same position in the PDF as they are in the original component.
i also try reactpdf.

autoplay video backgrounds in tailwind on safari desktop

I have a problem with the autoplay video background on the Safari desktop.
AutoPlay works fine in Firefox, Chrome etc, but not in Safari, how can I fix it?
Bellow my code:
<header class="relative flex items-center justify-center h-screen mb-12 overflow-hidden">
<div class="relative z-30 p-5 text-2xl text-white bg-purple-300 bg-opacity-50 rounded-xl">
Welcome to my site!
</div>
<video autoplay loop muted class="absolute z-10 w-auto min-w-full min-h-full max-w-none">
<source src="https://assets.mixkit.co/videos/preview/mixkit-set-of-plateaus-seen-from-the-heights-in-a-sunset-26070-large.mp4" type="video/mp4" />Your browser does not support the video tag.
</video>
</header>
<div class="max-w-lg m-auto">
<p class="mb-4">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec placerat a
magna non varius. Proin leo felis, euismod non porta eget, varius sit amet
sapien. Maecenas in nulla at leo convallis consectetur id a sapien. Nulla
nec pulvinar nisi. Vivamus non facilisis lacus, et volutpat libero. Nulla ac
odio aliquam, accumsan arcu ut, lacinia est. Nulla eu sem elit. Fusce nec
laoreet sem, semper molestie libero.
</p>
<p class="mb-4">
Ut sagittis lacus consequat accumsan venenatis. Sed sollicitudin, lectus et
fringilla ultrices, dolor nisi scelerisque tortor, vel finibus magna massa
non nunc. Phasellus massa quam, egestas a nisl sed, porta volutpat metus.
Nunc sed elit ac tellus tempor cursus. Suspendisse potenti. Vestibulum
varius rutrum nisl nec consequat. Suspendisse semper dignissim sem viverra
semper. Nulla porttitor, purus nec accumsan pharetra, nisi dolor condimentum
ipsum, id consequat nulla nunc in ligula.
</p>
<p class="mb-12">
Nulla pharetra lacinia nisi, vitae mollis tellus euismod id. Mauris porta
dignissim hendrerit. Cras id velit varius, fermentum lectus vitae, ultricies
dolor. In bibendum rhoncus purus vel rutrum. Nam vulputate imperdiet
fringilla. Donec blandit libero massa. Suspendisse dictum diam mauris, vitae
fermentum dolor tincidunt in. Pellentesque sollicitudin venenatis dolor,
vitae scelerisque elit ultrices eu. Donec eget sodales risus, quis dignissim
neque.
</p>
</div>
Live preview:
https://codepen.io/zdebskimatt/pen/yLqqZdN
ps.
How can I add a static image if the video does not play automatically on desktop, mobile?

How to rewrite class component to React Functional?

I am new to React and I am learning the basics, but right now I need to rewrite a Class component in order to use React Hooks. So I guess I need to rewrite it to a functional component.
I already tried changing some of the things but in the end everything breaks and I will get a 'props not defined' error.
This is the code:
class Main extends React.Component {
render() {
let close = (
<div
className="close"
onClick={() => {
this.props.onCloseArticle()
}}
></div>
)
return (
<div
ref={this.props.setWrapperRef}
id="main"
style={this.props.timeout ? { display: 'flex' } : { display: 'none' }}
>
<article
id="vision"
className={`${this.props.article === 'vision' ? 'active' : ''} ${
this.props.articleTimeout ? 'timeout' : ''
}`}
style={{ display: 'none' }}
>
<h2 className="major">Vision</h2>
<span className="image main">
<img src={pic01} alt="" />
</span>
<p>
Adipiscing magna sed dolor elit. Praesent eleifend dignissim arcu,
at eleifend sapien imperdiet ac. Aliquam erat volutpat. Praesent
urna nisi, fringila lorem et vehicula lacinia quam. Integer
sollicitudin mauris nec lorem luctus ultrices.
</p>
<p>
Nullam et orci eu lorem consequat tincidunt vivamus et sagittis
libero. Mauris aliquet magna magna sed nunc rhoncus pharetra.
Pellentesque condimentum sem. In efficitur ligula tate urna.
Maecenas laoreet massa vel lacinia pellentesque lorem ipsum dolor.
Nullam et orci eu lorem consequat tincidunt. Vivamus et sagittis
libero. Mauris aliquet magna magna sed nunc rhoncus amet feugiat
tempus.
</p>
{close}
</article>
</div>
)
}
}
Main.propTypes = {
route: PropTypes.object,
article: PropTypes.string,
articleTimeout: PropTypes.bool,
onCloseArticle: PropTypes.func,
timeout: PropTypes.bool,
setWrapperRef: PropTypes.func.isRequired,
}
export default Main
What I did is changing class main to const Main = () => {, remove the render() but after that I am confused..
This should do the work
Replace class by const
Remove the render lifecycle method used in class components
Add the props in the parameter of the function
Remove all the this
const Main = (props) => {
let close = (
<div
className="close"
onClick={() => {
props.onCloseArticle()
}}
></div>
)
return (
<div
ref={props.setWrapperRef}
id="main"
style={props.timeout ? { display: 'flex' } : { display: 'none' }}
>
<article
id="vision"
className={`${props.article === 'vision' ? 'active' : ''} ${
props.articleTimeout ? 'timeout' : ''
}`}
style={{ display: 'none' }}
>
<h2 className="major">Vision</h2>
<span className="image main">
<img src={pic01} alt="" />
</span>
<p>
Adipiscing magna sed dolor elit. Praesent eleifend dignissim arcu,
at eleifend sapien imperdiet ac. Aliquam erat volutpat. Praesent
urna nisi, fringila lorem et vehicula lacinia quam. Integer
sollicitudin mauris nec lorem luctus ultrices.
</p>
<p>
Nullam et orci eu lorem consequat tincidunt vivamus et sagittis
libero. Mauris aliquet magna magna sed nunc rhoncus pharetra.
Pellentesque condimentum sem. In efficitur ligula tate urna.
Maecenas laoreet massa vel lacinia pellentesque lorem ipsum dolor.
Nullam et orci eu lorem consequat tincidunt. Vivamus et sagittis
libero. Mauris aliquet magna magna sed nunc rhoncus amet feugiat
tempus.
</p>
{close}
</article>
</div>
)
}

React Table with Material UI context menu

I am having trouble getting the Material UI Menu to work with React Table#v6.
I want to be able to right-click anywhere in the table (row, td) and show a context menu. This part is working.
But I also want to be able to continuously right-click other locations in the table and always show the context menu the cursor location. This is not working. Currently, you have to click-away to close the menu and then right-click again to re-open the menu.
In the Material UI demo this is working fine:
https://material-ui.com/components/menus/#context-menu
I adopted the example above to work with React Table, but it's not quite working as expected.
My example adoption:
https://codesandbox.io/s/aged-leaf-0nf6b?file=/src/index.js
Any Ideas how to get this to work as in the example?
This is because you added onContextMenu props to Td, not the table container.
Move onContext Menu to container div, like this:
<div onContextMenu={(e) => {
e.preventDefault();
console.log("context menu");
this.setState({
mouseX: e.clientX - 2,
mouseY: e.clientY - 4
});
}}>
And it should work.
Enjoy!
I ended up creating a popper context menu to replicate all the material-ui behavior for menus.
import React from "react";
import Popper from "#material-ui/core/Popper";
import Typography from "#material-ui/core/Typography";
import MenuList from "#material-ui/core/MenuList";
import MenuItem from "#material-ui/core/MenuItem";
import Paper from "#material-ui/core/Paper";
import { makeStyles } from "#material-ui/core/styles";
import { ClickAwayListener, Fade } from "#material-ui/core";
/* copied from https://github.com/mui-org/material-ui/blob/v4.3.2/packages/material-ui/src/Menu/Menu.js#L21 */
const useMenuStyles = makeStyles({
/* Styles applied to the `Paper` component. */
paper: {
// specZ: The maximum height of a simple menu should be one or more rows less than the view
// height. This ensures a tapable area outside of the simple menu with which to dismiss
// the menu.
maxHeight: "calc(100% - 96px)",
// Add iOS momentum scrolling.
WebkitOverflowScrolling: "touch"
},
/* Styles applied to the `List` component via `MenuList`. */
list: {
// We disable the focus ring for mouse, touch and keyboard users.
outline: 0
}
});
export default function FakedReferencePopper() {
const [open, setOpen] = React.useState(false);
const [anchorEl, setAnchorEl] = React.useState<null | any>(null);
const handleClose = () => {
setOpen(false);
};
const handleContextMenu = (e) => {
e.preventDefault();
const { clientX, clientY } = e;
setOpen(true);
const virtualElement = {
getBoundingClientRect: () => ({
width: 0,
height: 0,
top: clientY,
right: clientX,
bottom: clientY,
left: clientX
})
};
setAnchorEl(virtualElement);
};
const id = open ? "faked-reference-popper" : undefined;
const menuClasses = useMenuStyles();
return (
<div>
<div onContextMenu={handleContextMenu}>
<Typography aria-describedby={id}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ipsum
purus, bibendum sit amet vulputate eget, porta semper ligula. Donec
bibendum vulputate erat, ac fringilla mi finibus nec. Donec ac dolor
sed dolor porttitor blandit vel vel purus. Fusce vel malesuada ligula.
Nam quis vehicula ante, eu finibus est. Proin ullamcorper fermentum
orci, quis finibus massa. Nunc lobortis, massa ut rutrum ultrices,
metus metus finibus ex, sit amet facilisis neque enim sed neque.
Quisque accumsan metus vel maximus consequat. Suspendisse lacinia
tellus a libero volutpat maximus. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nullam ipsum purus, bibendum sit amet
vulputate eget, porta semper ligula. Donec bibendum vulputate erat, ac
fringilla mi finibus nec. Donec ac dolor sed dolor porttitor blandit
vel vel purus. Fusce vel malesuada ligula. Nam quis vehicula ante, eu
finibus est. Proin ullamcorper fermentum orci, quis finibus massa.
Nunc lobortis, massa ut rutrum ultrices, metus metus finibus ex, sit
amet facilisis neque enim sed neque. Quisque accumsan metus vel
maximus consequat. Suspendisse lacinia tellus a libero volutpat
maximus. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nullam ipsum purus, bibendum sit amet vulputate eget, porta semper
ligula. Donec bibendum vulputate erat, ac fringilla mi finibus nec.
Donec ac dolor sed dolor porttitor blandit vel vel purus. Fusce vel
malesuada ligula. Nam quis vehicula ante, eu finibus est. Proin
ullamcorper fermentum orci, quis finibus massa. Nunc lobortis, massa
ut rutrum ultrices, metus metus finibus ex, sit amet facilisis neque
enim sed neque. Quisque accumsan metus vel maximus consequat.
Suspendisse lacinia tellus a libero volutpat maximus. Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Nullam ipsum purus,
bibendum sit amet vulputate eget, porta semper ligula. Donec bibendum
vulputate erat, ac fringilla mi finibus nec. Donec ac dolor sed dolor
porttitor blandit vel vel purus. Fusce vel malesuada ligula. Nam quis
vehicula ante, eu finibus est. Proin ullamcorper fermentum orci, quis
finibus massa. Nunc lobortis, massa ut rutrum ultrices, metus metus
finibus ex, sit amet facilisis neque enim sed neque. Quisque accumsan
metus vel maximus consequat. Suspendisse lacinia tellus a libero
volutpat maximus. Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Nullam ipsum purus, bibendum sit amet vulputate eget, porta
semper ligula. Donec bibendum vulputate erat, ac fringilla mi finibus
nec. Donec ac dolor sed dolor porttitor blandit vel vel purus. Fusce
vel malesuada ligula. Nam quis vehicula ante, eu finibus est. Proin
ullamcorper fermentum orci, quis finibus massa. Nunc lobortis, massa
ut rutrum ultrices, metus metus finibus ex, sit amet facilisis neque
enim sed neque. Quisque accumsan metus vel maximus consequat.
Suspendisse lacinia tellus a libero volutpat maximus. Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Nullam ipsum purus,
bibendum sit amet vulputate eget, porta semper ligula. Donec bibendum
vulputate erat, ac fringilla mi finibus nec. Donec ac dolor sed dolor
porttitor blandit vel vel purus. Fusce vel malesuada ligula. Nam quis
vehicula ante, eu finibus est. Proin ullamcorper fermentum orci, quis
finibus massa. Nunc lobortis, massa ut rutrum ultrices, metus metus
finibus ex, sit amet facilisis neque enim sed neque. Quisque accumsan
metus vel maximus consequat. Suspendisse lacinia tellus a libero
volutpat maximus.
</Typography>
</div>
<Popper
id={id}
open={open}
anchorEl={anchorEl}
transition
placement="bottom-start"
>
{({ TransitionProps }) => (
<ClickAwayListener onClickAway={handleClose}>
<Fade {...TransitionProps}>
<Paper className={menuClasses.paper}>
<MenuList className={menuClasses.list} autoFocus>
<MenuItem onClick={handleClose}>Profile</MenuItem>
<MenuItem onClick={handleClose}>My account</MenuItem>
<MenuItem onClick={handleClose}>Logout</MenuItem>
</MenuList>
</Paper>
</Fade>
</ClickAwayListener>
)}
</Popper>
</div>
);
}
Here is codesandbox
https://codesandbox.io/s/popper-context-menu-t1u6r

How to Make Angular Material Tabs as Wizard with ng-click?

I would like to Make <md-tab>s as Wizard by adding Next Button.
i added My code and created a Plunker with next Buttons Could guys take a look please add your code to make it wizard
Plunker Added :-
http://plnkr.co/edit/p9mMyaqqHWtVyAEeisd1?p=preview
<md-content class="md-padding">
<md-tabs md-dynamic-height="" md-border-bottom="">
<md-tab label="one">
<md-content class="md-padding">
<h1 class="md-display-2">Tab One</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla venenatis ante augue. Phasellus volutpat neque ac dui mattis vulputate. Etiam consequat aliquam cursus. In sodales pretium ultrices. Maecenas lectus est, sollicitudin consectetur felis nec, feugiat ultricies mi.</p>
<md-button class="md-raised md-primary">Next</md-button>
</md-content>
</md-tab>
<md-tab label="two">
<md-content class="md-padding">
<h1 class="md-display-2">Tab Two</h1>
<p>Lorem risus, pulvinar at interdum quis, vehicula sed odio. Phasellus in enim venenatis, iaculis tortor eu, bibendum ante. Donec ac tellus dictum neque volutpat blandit. Praesent efficitur faucibus risus, ac auctor purus porttitor vitae. Phasellus ornare dui nec orci posuere, nec luctus mauris semper.</p>
<md-button class="md-raised md-primary">Next</md-button>
</md-content>
</md-tab>
<md-tab label="three">
<md-content class="md-padding">
<h1 class="md-display-2">Tab Three</h1>
<p>Integer turpis erat, porttitor vitae mi faucibus, laoreet interdum tellus. Curabitur posuere molestie dictum. Morbi eget congue risus, quis rhoncus quam. Suspendisse vitae hendrerit erat, at posuere mi. Cras eu fermentum nunc. Sed id ante eu orci commodo volutpat non ac est. Praesent ligula diam, congue eu enim scelerisque, finibus commodo lectus.</p>
<md-button class="md-raised md-primary">Finish</md-button>
</md-content>
</md-tab>
</md-tabs>
you have add an attribute to your md-tabs tag md-selected attribute to set the selected tab index ..
so first you have to add ng-controller
<md-content class="md-padding" ng-controller="tabCtrl">
after bind you have bind the value of selectedIndex
<md-tabs md-dynamic-height="" md-border-bottom="" md-selected="selectedIndex">
after you have to add ng-click to your button to call nextTab()
<md-button class="md-raised md-primary" ng-click="nextTab()">Next</md-button>
end of it ... here is the controller you need
// Code goes here
var moduler = angular.module('MyApp', ['ngMaterial']);
moduler.controller("tabCtrl", ['$scope', function($scope) {
$scope.max = 2;
$scope.selectedIndex = 0;
$scope.nextTab = function() {
var index = ($scope.selectedIndex == $scope.max) ? 0 : $scope.selectedIndex + 1;
$scope.selectedIndex = index;
};
}]);
i hope this example helps you...
here is the example at plunker as you wish
http://plnkr.co/edit/iNEXWXUBDvsrKgUSelkW?p=preview
you could use the Wizard also which serves your cause
github Link :-
https://github.com/Matesign/material-wizard
sample code follows
<mt-wizard btn-progress-color="#D8D8D8" btn-bg-color="#FAFAFA" active-btn-bg-color="#E9E9E9" chevrons-always-visible="true" on-finish="submit()">
<mt-wz-step title="Step 1" step-img="step1.svg" on-exit="onExitStep1()">
</mt-wz-step>
</mt-wizard>
http://plnkr.co/edit/rp5qJykW2DD1A7EvaVZP?p=preview

Resources