开发者

jQuery - help with porting to a plugin

开发者 https://www.devze.com 2023-02-25 04:21 出处:网络
just wondering if anyone could have a look at my code that ive been trying to port to a plugin. There seem to be no errors getting logged, I just cant work out not working (this is my first attempt at

just wondering if anyone could have a look at my code that ive been trying to port to a plugin. There seem to be no errors getting logged, I just cant work out not working (this is my first attempt at a jQuery plugin so I really don't quite know what I'm doing, even though I've done a lo开发者_StackOverflow社区t of work with the jQuery library).

Here is the original code (with comments):

http://jsfiddle.net/GZLQH/1/

And this is my attempt and a plugin:

http://jsfiddle.net/PnEYN/

Cheers

Charlie


Here you go: http://jsfiddle.net/aGFdJ/4/

The main point:

  • Since the this pointer does not always point to the original element, you need to store a reference to it somewhere.

Side notes:

  • As experimentX noted in the comments, you need to reference jQuery.
  • background:url(spark_01.png) is not going to work in jsFiddle.
  • Consider using a for(var i = 0; i < sparks.length; i++) when looping over a array, instead of the for(var key in sparks).
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号