Zurb Foundation Interchange not working, 'nodeName' undefined

∥☆過路亽.° 提交于 2020-01-02 07:18:30

问题


I'm trying to use interchange to change images based on the screen size.

However, when interchange is initialised no images load. Then when I resize the browser (1024px and lower) I get an error in the console saying:

Uncaught TypeError: Cannot read property 'nodeName' of undefined 

Which relates to line 47 of foundation.interchange.js, which is:

if (/IMG/.test(el[0].nodeName)) {

The code I'm trying to use is:

<img data-interchange="[http://www.example.com/image.png, (default)], [http://www.exmaple.com/image-large.png, (large)]" />

This is completely standard as per Zurb's documentation. I've made sure the images exist, which they do.

I'm using Foundation version 5.2.2.

Any ideas?


回答1:


I had this issue and resolved it by doing some simple tests...

Try some of these:

  1. Check - You are only calling one instance of the script path 'interchange.js'

Why? - This will ensure that you avoid duplicate function calls within the plugin.

How? - Ctrl-f (find) the word 'interchange.js' on the view source page

This is the best way to check for it, especially if you're working in an MVC or nested webforms framework.

  1. Check - $(document).foundation(); is called after the interchange.js script has loaded

eg. IN THIS ORDER....

<script src="/foundation/foundation.js")></script>
<script src="/foundation/foundation.interchange.js"></script>

<script type="text/javascript">
    $(document).ready(function () {

        $(document).foundation();

     });
</script>

Why? - The interchange needs to exist already once foundation intializes I believe.

I hope these options help - sorry if it's a bit basic - but worth a try all the same Cheers



来源:https://stackoverflow.com/questions/25873237/zurb-foundation-interchange-not-working-nodename-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!