/    Sign up×
Community /Pin to ProfileBookmark

Get initial window with

This script changes the color when resizing.

https://jsfiddle.net/Lr7uwz8n/2/

But this script is not fired on load. Just when resized.
How can I do both initial width and when resizing?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@cootheadJun 26.2021 — Hi there sibert,

there is no need to use [i]JavaScript[/i] when [i]CSS[/i] will easily do the job. ;)

<i>
</i>&lt;!DOCTYPE HTML&gt;
&lt;html lang="en"&gt;
&lt;head&gt;

&lt;meta charset="utf-8"&gt;
&lt;meta name="viewport" content="width=device-width,height=device-height,initial-scale=1"&gt;

&lt;title&gt;CSS background colours&lt;/title&gt;

&lt;!--
The internal CSS should be transferred to an external file
&lt;link rel="stylesheet" href="screen.css" media="screen"&gt;
--&gt;

&lt;style media="screen"&gt;
body {
background-color: #ffc0cb;
font: normal 1em / 1.5em sans-serif;
transition: background-color 1s ease-in-out; <br/>
}
@media (max-width: 75em) {
body{
background-color: #7fffd4;
transition: background-color 1s ease-in-out;
}
}
@media (max-width: 64em) {
body{
background-color: #0f0;
transition: background-color 1s ease-in-out;
}
}
@media (max-width: 50em) {
body{
background-color: #00f;
transition: background-color 1s ease-in-out;
}
}
@media (max-width: 40em) {
body{
background-color: #0ff;
transition: background-color 1s ease-in-out;
}
}
@media (max-width: 25em) {
body{
background-color: #f0f;
transition: background-color 1s ease-in-out;
}
}
@media (max-width: 20em) {
body{
background-color: #ff0;
transition: background-color 1s ease-in-out;
}
}
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;/body&gt;
&lt;/html&gt;



[i]coothead[/i]
Copy linkTweet thisAlerts:
@sibertauthorJun 28.2021 — > @coothead#1633389 there is no need to use JavaScript when CSS will easily do the job.

You did not get the full description. Sorry.

The aim was to fire doubleclick or click depinding on window size. And this smells Javascript to me.

Though I found a interim solution in "agGrid script"

``<i>
</i> onRowDoubleClicked(params) {
if (window.innerWidth &lt; 1751) {
getcard(params.data.que_id,window.innerWidth)
}
},

onRowClicked(params) {
if (window.innerWidth &gt; 1750) {
getcard(params.data.que_id,window.innerWidth)
}
},<i>
</i>
``


The final interim result is here: https://form.go4webdev.org/aggrid
×

Success!

Help @sibert spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...