我想制作一个 html/js 小部件,人们可以将其添加到他们的博客、网站等中.
I would like to make a html/js widget that people can add to their blogs, sites etc.
我以前从未制作过小部件,所以我想知道应该做什么,不应该做什么.例如,如何制作样式?内联,自己的css文件或最佳做法是什么?我相信我不能在里面使用头部和身体的东西.那么h1,h2等呢?他们会搞砸有小部件的网站还是我可以使用它们?
I have never made widgets before so I would like to hear what should be done and what not. For example, how do I make the styling? Inline, own css file or what is the best practise? I believe i cant use head and body stuff in it. What about h1, h2 etc? Do they screw the website that has the widget or can i use them?
如果你有什么好的建议,我想听听.
If you have any good tips I would like to hear those.
谢谢.
我会尝试:
使其可配置
通过这样做,您可以让用户决定他是否希望您的小部件自动加载样式表,或者他是否想自己托管它.如果这样做,他还可以更新样式以更好地适应小部件所在的页面.
By doing this you let the user decide if he wants your widget to automatically load the stylesheet, or if he wants to host it himself. If he does, he can also update the styles to better fit the page the widget resides on.
ExampleComWidget.addListener('update', callback);
ExampleComWidget.addListener('update', callback);
使用巧妙的标记
确保对你的类和 id 使用范围,尽可能避免冲突
Be sure to use scoping on your classes and ids, to avoid conflicts as much as possible
即如果您的公司名称是 example.com,您可以使用如下类:com-ex-widget-newsItem
I.e. if your company's name is example.com, you could use classes like: com-ex-widget-newsItem
这篇关于小部件 - 做什么和不做什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!