简体   繁体   中英

node-webkit: doesn't show active content?

I have a small nw.js app that alters the div section of the index.html page:

var myDiv = document.getElementById("outputSection");
var myImg = document.createElement("img");
myDiv.appendChild(myImg);

myImg.src = 'http://127.0.0.2:8080/prime_almost_full_00007.0001.png';
myImg.width = '256';
myImg.height = '256';
myImg.class = 'reel';
myImg.id = 'image';
myImg.setAttribute("data-images", 'http://127.0.0.2:8080/prime_almost_full_00007.####.png|0001..0250');

The HTML code I'm trying to mimic in my static example, which works, is:

<img src='http://127.0.0.2:8080/prime_almost_full_00007.0001.png'width='256' height='256' class='reel' id='image' data-images='http://127.0.0.2:8080/prime_almost_full_00007.####.png|0001..0021'>

I'm using the Jquery-reels library. At the top of my page, I include it thusly:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src='http://code.vostrel.cz/jquery.reel.js' type='text/javascript'></script>

For some reason, while the image shows up with the first code snipped, it isn't interactive. My static page, which works is like this:

<!DOCTYPE html>
<html>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src='http://code.vostrel.cz/jquery.reel.js' type='text/javascript'></script>

<head>
  <title>Hi there</title>
</head>
<body>
    <div>
    <img src='http://127.0.0.2:8080/prime_almost_full_00007.0001.png' 
         width='256' 
         height='256' 
         class='reel' 
         id='image' 
         data-images='http://127.0.0.2:8080/prime_almost_full_00007.####.png|0001..0021'>
    </div>
</body>
</html>

It's not clear to me why this is happening. Is it something about node-webkit?

EDIT: re-scanning doesn't seem to work:

myDiv.innerHTML = "<img src='http://127.0.0.2:8080/prime_almost_full_00007.0001.png' width='256' height='256' class='reel' id='image' data-images='http://127.0.0.2:8080/prime_almost_full_00007.####.png|0001..0021'>";
$.reel.scan();

When the page loads, the reel plugin automatically looks for elements with the attribute class="reel". See the annotated source for more info about this.

According to that documentation, since you are adding an element to the page after the page loads, you may need to call the $.reel.scan() function at the end of your javascript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM