Sifr and Javascript changing stylesheets (without a page refresh)

与世无争的帅哥 提交于 2019-12-02 10:21:49

Given sIFR 3, it is possible to change some of the CSS used to render the text.

I'm assuming you have two replacements, for h1 and h2, and we're only changing their color:

function changeColor(hexValue) {
  var css = '.sIFR-root { color: ' + hexValue + '; }';
  for (var i = 0; i < sIFR.replacements['h1'].length; i++) {
    sIFR.replacements['h1'][i].changeCSS(css);
  }
  for (var i = 0; i < sIFR.replacements['h2'].length; i++) {
    sIFR.replacements['h2'][i].changeCSS(css);
  }
}

// after switching stylesheet:
changeColor('#FF9900');

This should change the text color of the <h1> and <h2> replaced elements to orange.

The objects returned by sIFR.replacements[][] are FlashInteractors.

I haven't used sifr myself, but I think your best bet is the Rollback add-on. Then you should be able to effectively reload your sifr'd tags in your javascript by rolling back & then immediately "rolling forward" again by re-running your replacement statements (i.e. basically disabling & re-enabling it).

EDIT: Just noticed at the bottom of this page there's a redraw() method... might actually be exactly what you're after? (again, sorry for the vagueness, but I've never directly used sifr myself)

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