We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

How can i get variable from js file?

Home Forums Programming How can i get variable from js file?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #54582
    keith
    Customer

    Trying to enable/disable render with IntersectionObserver.
    How can i get variable (render) from file?

    
    const options = {
        threshold : 0
    }
    
    let render;
    
    const callback = function( entries, observer ) {
    
        entries.forEach( entry => {
    
            const { isIntersecting } = entry;
    
            if( isIntersecting ) {
                render = 1
            } else {
                render = 0
            }
    
        } );
    
    }
    
    const observer = new IntersectionObserver( callback );
    
    const target = document.querySelector( '#target' );
    observer.observe( target );
    
    #54590
    kdv
    Participant

    where is your code located and from where you want to read render? if your .js is included in .html than you can read this variable from any other .js that is also included in .html…

    Puzzles and JS coding. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.

    #54598
    keith
    Customer

    it`s located in parent index.html
    how can i read it ?

    
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <title>proj</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
     </head>
    <body>
      <div class="wrapper">
        <div class="b1">
          <img class="arrow" src="img\img2.png" />
        </div>
        <div id="target">
          <div class="btns">
                <button id="cam1"><img src="img\i1.png" /></button>
                <button id="cam2"><img src="img\i2.png" /></button>
                <button id="cam3"><img src="img\i3.png" /></button>
                <button id="cam4"><img src="img\i4.png" /></button>
                <button id="cam5"><img src="img\i5.png" /></button>
          </div>
          <iframe class="frame" frameborder="0" src="Conmet_demo.html"></iframe>
        </div>
        <div class="b3">
          <img class="arrow" src="img\img1.png" />
        </div>
      </div>
      <script src="src/index.js"></script>
    </body>
    
    #54606
    keith
    Customer

    Done. Thanks for help.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.