Setting CSS class to a specific div with specific style attribute

23
May 19, 2017, at 6:50 PM

I'm currently redoing a website (http://www.vins-de-fronton.com/) and I have some issues doing what I would like to do.

The guys who made it set the content area in some kind of a container and used 'my custom scrollbar' from malihu (http://manos.malihu.gr/jquery-custom-content-scroller/), I would like to keep them but I think it may cause some issues for what I'm trying to do, let me explain :

I want to add a scrolling parallax effect to my differents div and I was trying to do this with js, but all of the things I've tried need to use the normal scrollbar and its scrolled px, which is replaced by the custom scrollbar.

When you scroll up or down, the actual scrollbar set a specific style to the "#mCSB_1_container" div with 'top' changing depending of where you are in the page.

So I was thinking that maybe I could add a specific css class when the div #mCSB_1_container has top:-480px as style attribute (for exemple)? Using javascript maybe ?

Here is the div:

<div id="mCSB_1_container" class="mCSB_container" style="position: relative; top: -488px; left: 0px;" dir="ltr">

Thanks a lot for reading this, and I hope that I've well explained my issue :)

Cheers

Answer 1

Try this: you can read top value for the div and add CSS class as shown below

$(function(){
  var top = $("#mCSB_1_container").css('top');
  if(top=='-480px') {
      $("#mCSB_1_container").addClass("YourClass");
  }
});
READ ALSO
Using AJAX to Send Data on Button Click

Using AJAX to Send Data on Button Click

I have a table with multiple columns (indexphp)

51
How to format a number to currency R$, or $ to R$?

How to format a number to currency R$, or $ to R$?

How Can I format a simple number or $ format to Brazilian currency R$ - Real? I tried some ways to do this like maskMoney() plugin (I think that working just for inputs) but unsuccessfully

15
createRecord with custom ID in emberjs 2.x and Firebase 3.x

createRecord with custom ID in emberjs 2.x and Firebase 3.x

Until now, I saved all my data with the following line of code:

35
How to get a File() or Blob() from an URL in javascript?

How to get a File() or Blob() from an URL in javascript?

I try to upload an image to the Firebase storage from an URL (with ref()put(file))(www

29