Call additional option methods in JavaScript

Tomster

I'm using stickjs script and can't seem to call "options" method in code. I've pasted it below.

I'm not sure if I need first initialize "options" ie. .sticky(options ({options_here, option_2});

I've tried both ways, but it is till not calling another css class when the div sticks to top:

You can see I've done for 2 options: { topSpacing: 0, className: "#newheader" } - #newheader should be showing a different color per CSS.

What am I missing? Thanks!

<html>
<head>
  <title>Sticky Plugin</title>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  <script type="text/javascript" src="jquery.sticky.js"></script>
  <script>
    $(window).load(function(){
      $("#header").sticky({ topSpacing: 0, className: "#newheader" })
    });

  </script>


  <style>
    body {
      height: 10000px;
      padding: 0;
      margin: 0;
    }

    #header {
      background: #bada55;
      color: white;
      font-family: Droid Sans;
      font-size: 18px;
      line-height: 1.6em;
      font-weight: bold;
      text-align: center;
      padding: 10px;
      text-shadow: 0 1px 1px rgba(0,0,0,.2);
      width:100%;
      box-sizing:border-box;
    }

    #newheader {
    background: #FF0004;
      color:#0056F2;
      font-family: Droid Sans;
      font-size: 24px;
      line-height: 1.6em;
      font-weight: bold;
      text-align: center;
      padding: 10px;
      text-shadow: 0 1px 1px rgba(0,0,0,.2);
      width:100%;
      box-sizing:border-box;
    }
  </style>
</head>
<body>
  <p>This is test this is text this is text at the top.</p>
  <div id="header">
    <p>This is the sticky thingy that is really cool.</p>
  </div>
  <p>This is test this is text this is text at the bottom.</p>
</body>
</html>
Steven Web

The ClassName property adds a CLASS-name to the element. So its no ID!! Try:

$("#header").sticky({ topSpacing: 0, className: "newheader" });

And alter your css like:

 .newheader {
      background: #FF0004;
      .....
  }

UPDATE:

After reading the Sticky documentation it was clear... The new class will be added to the parent element. So you must change you css cascading to:

.newheader #header {
   background: #FF0004;
   color:#0056F2;
   font-family: Droid Sans;
   font-size: 24px;
   line-height: 1.6em;
   font-weight: bold;
   text-align: center;
   padding: 10px;
   text-shadow: 0 1px 1px rgba(0, 0, 0, .2);
   width:100%;
   box-sizing:border-box;
 }

That will save your day!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to call managed bean methods with parameters via JavaScript

From Dev

Uncaught Error: cannot call methods on resizable prior to initialization; attempted to call method 'option'

From Dev

Can't call methods on subclass of native window object in javascript

From Dev

Call Android methods from JavaScript

From Dev

Call native objective methods from JavaScript using JavaScript core framework

From Dev

How to call javascript methods on click function?

From Dev

Adding additional methods for a thread in Java?

From Dev

Adding additional methods to JPA entity

From Dev

Object Oriented, inheritance in javascript unable to call external methods

From Dev

Extending existing Object to add additional JavaScript Prototype methods

From Dev

Javascript call methods from nested objects in loop

From Dev

Can static methods in javascript call non static

From Dev

javascript apply and call methods and chain together

From Dev

Defining Additional Methods in a Scrapy Class

From Dev

Additional spaces in angularjs select option

From Dev

How to call two methods one by one in javascript?

From Dev

Best NVIDIA Additional Driver Option

From Dev

Function call with additional sub functions

From Dev

How to call java methods inside javascript

From Dev

Can't call methods on subclass of native window object in javascript

From Dev

JavaScript runtime error: can't call methods on dialog prior to initialization; tried to call 'close'

From Dev

Call native objective methods from JavaScript using JavaScript core framework

From Dev

How to call javascript methods on click function?

From Dev

Adding additional methods for a thread in Java?

From Dev

Object Oriented, inheritance in javascript unable to call external methods

From Dev

Javascript call methods from nested objects in loop

From Dev

Iterate over javascript object such that key variables are used as methods to call the object

From Dev

Error: cannot call methods on tabs prior to initialization; attempted to call method 'option'

From Dev

Passing an additional argument in call to a function

Related Related

  1. 1

    How to call managed bean methods with parameters via JavaScript

  2. 2

    Uncaught Error: cannot call methods on resizable prior to initialization; attempted to call method 'option'

  3. 3

    Can't call methods on subclass of native window object in javascript

  4. 4

    Call Android methods from JavaScript

  5. 5

    Call native objective methods from JavaScript using JavaScript core framework

  6. 6

    How to call javascript methods on click function?

  7. 7

    Adding additional methods for a thread in Java?

  8. 8

    Adding additional methods to JPA entity

  9. 9

    Object Oriented, inheritance in javascript unable to call external methods

  10. 10

    Extending existing Object to add additional JavaScript Prototype methods

  11. 11

    Javascript call methods from nested objects in loop

  12. 12

    Can static methods in javascript call non static

  13. 13

    javascript apply and call methods and chain together

  14. 14

    Defining Additional Methods in a Scrapy Class

  15. 15

    Additional spaces in angularjs select option

  16. 16

    How to call two methods one by one in javascript?

  17. 17

    Best NVIDIA Additional Driver Option

  18. 18

    Function call with additional sub functions

  19. 19

    How to call java methods inside javascript

  20. 20

    Can't call methods on subclass of native window object in javascript

  21. 21

    JavaScript runtime error: can't call methods on dialog prior to initialization; tried to call 'close'

  22. 22

    Call native objective methods from JavaScript using JavaScript core framework

  23. 23

    How to call javascript methods on click function?

  24. 24

    Adding additional methods for a thread in Java?

  25. 25

    Object Oriented, inheritance in javascript unable to call external methods

  26. 26

    Javascript call methods from nested objects in loop

  27. 27

    Iterate over javascript object such that key variables are used as methods to call the object

  28. 28

    Error: cannot call methods on tabs prior to initialization; attempted to call method 'option'

  29. 29

    Passing an additional argument in call to a function

HotTag

Archive