/    Sign up×
Community /Pin to ProfileBookmark

How can I remove the css

How can I remove cssSetyle if the counter is not === 3?

[code]
if (counter === 3) {
const sideBar = document.querySelector(“.side-bar”);
const navButtons = document.querySelector(“.buttons”);

const cssStyle = “opacity: 0; pointerEvents: none”;
const transitionSetyle = “opacity 200ms ease-in”;

sideBar.style.cssText = cssStyle;
navDots.style.cssText = cssStyle;
navButtons.style.cssText = cssStyle;

sideBar.style.transition = transitionSetyle;
navDots.style.transition = transitionSetyle;
navButtons.style.transition = transitionSetyle;

// sections[3].style.overflow = “scroll”;
} else {
const removeCssStyle = “”;

sideBar.style.cssText = removeCssStyle;
navDots.style.cssText = removeCssStyle;
navButtons.style.cssText = removeCssStyle;
}
[/code]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@cootheadSep 15.2019 — Hi there RaulRogojan,

instead of using javascript to manipulate CSS conditions,

use it to add and remove CSS classes. ;)

Here is a basic example...

``<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;Remove CSS from Javascript&lt;/title&gt;

&lt;!--&lt;link rel="stylesheet" href="screen.css" media="screen"&gt;--&gt;

&lt;style media="screen"&gt;
body {
background-color: #f9f9f9;
font: normal 1em / 1.5em BlinkMacSystemFont, -apple-system, 'Segoe UI', roboto, helvetica, arial, sans-serif;
}
h1 {
font-size:1.5em;
color: #555;
text-align:center;
}

#button {
display:inline-block;
padding: 0.5em 1em;
border: 1px solid #999;
border-radius: 0.75em;
background-image: linear-gradient( to bottom, #fff, #ccc );
box-shadow: 0.25em 0.25em 0.25em rgba( 0, 0, 0, 0.4 );
font-size: 1.5em;
cursor: pointer;
}

#lorem {
box-sizing: border-box;
max-width: 50em;
padding: 2em;
margin: auto;
border: 1px solid #999;
border-radius: 0.75em;
background-color: #fff;
box-shadow: inset 0 0 0 rgba( 0, 0, 0, 0.4 ),
0.25em 0.25em 0.25em rgba( 0, 0, 0, 0.4 );
transition: opacity 1.5s ease-in-out;
}

.hide {
opacity: 0

}

.show {
opacity: 1;
}
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Remove CSS from Javascript&lt;/h1&gt;
&lt;input id="button" type="button" value="show"&gt;

&lt;p id="lorem" class="hide"&gt;
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Curabitur sit amet sem sed libero bibendum tempus faucibus
quis mi. Nulla rhoncus vel ipsum in volutpat. Nam tortor
nibh, posuere ac lorem ut
&lt;/p&gt;

&lt;script&gt;
(function( d ) {
'use strict';
var count = 0,
lor = d.querySelector( '#lorem' ),
but = d.querySelector( '#button' );

but.addEventListener( 'click' ,
function() {
if ( count === 0 ) {
lor.classList.remove( 'hide' );
lor.classList.add( 'show' );
but.value = 'hide'
count = 1;
}
else {
lor.classList.remove( 'show' );
lor.classList.add( 'hide' );
but.value = 'show'
count = 0;
}

}, false );
}( document ));
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;<i>
</i>
``


_coothead_
Copy linkTweet thisAlerts:
@codyhillauthorSep 15.2019 — @coothead#1608761 Thx! I changed that but it also doesn't work. What I am trying to achieve is when the section 4 is in view, the fixed elements have opacity and pointer-events none. But when another section is in view I want them to be visible even after they here hidden.

here is the code so you can understand it better: https://codepen.io/raul-rogojan/pen/KKPBpXJ?editors=0010

Basically, when you scroll down and get to section 4 I want them went, but when you scroll back up to section 3 I want them back.
Copy linkTweet thisAlerts:
@cootheadSep 15.2019 — Hi there RaulRogojan,

if you do not feel comfortable using CSS classes,

then you will need to use these...

  • 1. `` getComputedStyle()`</C></LI>
    <LI>2. <C>
    `getPropertyValue()``


  • **Further reading:-**

    [url=https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle][color=#069]MDN - window.getComputedStyle()[/color][/url]

    _coothead_
    Copy linkTweet thisAlerts:
    @codyhillauthorSep 15.2019 — @coothead#1608764 I did use classes. The code just doesn't work how I wanted.
    Copy linkTweet thisAlerts:
    @cootheadSep 15.2019 — > @RaulRogojan#1608765
    >
    > **[color=#069]I did use classes. The code just doesn't work how I wanted.[/color]**


    That's why I suggested that you looked into

    ``getComputedStyle()`` methodology. ;)

    _coothead_
    Copy linkTweet thisAlerts:
    @codyhillauthorSep 16.2019 — @coothead#1608767 Np, I made it work. I don't know how correct is, but it works.
    ×

    Success!

    Help @codyhill 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.20,
    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,
    )...