So when user clicks a button I want to open a popUp, depending on the width of the page I want to resize the popUp accordingly.
Found a tasty wee example How to detect responsive breakpoints of Twitter Bootstrap 3 using JavaScript?
// Executes only in XS breakpoint
if( viewport.is('xs') ) {
// ...
}
// Executes in SM, MD and LG breakpoints
if( viewport.is('>=sm') ) {
// ...
}
// Executes in XS and SM breakpoints
if( viewport.is('<md') ) {
// ...
}
Problem is viewpoint is firing as not defined
Uncaught ReferenceError: viewport is not defined
at <anonymous>:1:1
but I have included it in my head
<!--Viewport-->
<meta name="viewport" content="width=device-width, initial-scale=1">
I have also moved the bootstrap scripts from the head to the body.
Does anyone have any idea whats wrong?
ta
2
Answers
I think they meaning “viewport” as string that you should pass to the function.
so then you can return the size as string and check
if(viewport.is('md'))
and etc…
You need to declare the
viewport
variable in javascript.In the example it’s done using an IIFE as follows:
The viewport isset to ResponsiveBootstrapToolkit so you have to include the responsive-bootstrap-toolkit in your project.