问题描述:

I need to create a website which propagates internal links without page refresh. The navigation will stay constant. The content will be loaded via jQuery .load().

Everything works fine except that the jQuery plugin for full-screen background couldn't be loaded via AJAX. Each page has a different set of backgrounds. I am using [Vegas Background jQuery Plugin][1].

What I did is to place the function which fires off the plugin within the #content, which is loaded via AJAX. Something like this:

<div id="#content"> <!--Loaded via AJAX -->

<script>

$.vegas({

src:'images/anImageforThisPage.jpg',

fade:2000

});

</script>

<!-- OTHER CONTENT -->

</div>

But it does not works, each time when a link is clicked, only the contents are loaded, the background itself is still anImageforThisPage.jpg instead of theImageforAnotherPage.jpg

I'm not very sure why it behaves this way and is looking for a solution. I know .load() allows a callback function, tried it, still the same.

网友答案:

Your javascript needs to be wrapped in script tags.

<div id="#content"> <!--Loaded via AJAX -->
    <script type="text/javascript">
    $.vegas({
        src:'images/anImageforThisPage.jpg',
        fade:2000
    });
    </script>
   <!-- OTHER CONTENT -->
</div>
相关阅读:
Top