Skip to content

Commit 10dac07

Browse files
Merge pull request #29 from tomik23:onResize
feat: onResize
2 parents b69d0bc + bff4b88 commit 10dac07

22 files changed

+113
-24
lines changed

README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ See the demo - [example](https://tomik23.github.io/lazy-youtube-embed/)
3939
#### You can download from CDN as well
4040
```html
4141
<!-- CSS -->
42-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/tomik23/[email protected].4/dist/css/youtubeLazy.min.css"/>
42+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/tomik23/[email protected].5/dist/css/youtubeLazy.min.css"/>
4343

4444
<!-- JS -->
45-
<script src="https://cdn.jsdelivr.net/gh/tomik23/[email protected].4/dist/js/youtubeLazy.min.js"></script>
45+
<script src="https://cdn.jsdelivr.net/gh/tomik23/[email protected].5/dist/js/youtubeLazy.min.js"></script>
4646
```
4747

4848

@@ -54,6 +54,8 @@ See the demo - [example](https://tomik23.github.io/lazy-youtube-embed/)
5454
- **"openIn"** - this parameter allows you to display a button which, when clicked, directly opens the youtube page with the movie. For full functionality you need the corresponding parameter also added to js, see below `createWatchIn: () => {}`
5555
- **"title"** - the title of the video, it is displayed top of container`
5656
- **"picture"** - the parameter is responsible for generating a thumbnail. `TRUE` - generates picture + source + img. `FALSE` - only generate an img thumbnail
57+
- **onResize** - this function allows you to change the way the movie is started. We check the width of the window, in the example we set it to 800px, if this value is smaller than assumed, the movie will open in the same place without a lightbox, if greater than 800px, we will open the movie in the lighbox.
58+
5759

5860
```html
5961
<!-- default -->
@@ -122,7 +124,23 @@ See the demo - [example](https://tomik23.github.io/lazy-youtube-embed/)
122124
</a>
123125
</div>
124126
`)
125-
}
127+
},
128+
onResize: () => {
129+
let responsiveMin = 800;
130+
131+
// we check the width of the browser window
132+
const windowWidth =
133+
window.innerWidth ||
134+
document.documentElement.clientWidth ||
135+
document.body.clientWidth;
136+
137+
// we return the logical value "true/false"
138+
// if "true" then the movie is opened in the place
139+
// of display, if "false" the movie is opened in lightbox
140+
const widthWindow = windowWidth < responsiveMin ? true : false;
141+
142+
return widthWindow;
143+
},
126144
};
127145
128146
// ytLazy__item youtube class div with options
@@ -156,8 +174,8 @@ If you need IE support, add this pollyfil to html
156174

157175
### cdn
158176

159-
- https://cdn.jsdelivr.net/gh/tomik23/[email protected].4/dist/js/youtubeLazy.ie.min.js
160-
- https://cdn.jsdelivr.net/gh/tomik23/[email protected].4/dist/css/youtubeLazy.ie.min.css
177+
- https://cdn.jsdelivr.net/gh/tomik23/[email protected].5/dist/js/youtubeLazy.ie.min.js
178+
- https://cdn.jsdelivr.net/gh/tomik23/[email protected].5/dist/css/youtubeLazy.ie.min.css
161179

162180
## License
163181

dist/css/youtubeLazy.ie.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)