2012-04-17 2 views
1

를 추가 나는이 DOM에 새 CSS 규칙을 추가 할 수 있도록 Rule PluginjQuery를 규칙 플러그인 - 내 프로젝트를 위해 새 규칙

그것의 위대한처럼 보이는 jQuery를 사용할 필요가있다.

하지만 어떻게 새 규칙을 만들고이를 dom에 추가 할 수 있습니까 ??

These are the methods, the plugin adds to the different namespaces. 

jQuery.fn 
- sheet: returns the stylesheets from the matched styles and links. 
- cssRules: return all the rules from all the given sheets. 
- ownerNode: returns the nodes that belong to the given sheet (opposite to sheets). 
- cssText: returns the text of the first matched style/link. 

jQuery.rule 
- constructor($.rule): 
    - 1st argument: nothing, a rule filter, rule literal, css rule or array of rules. 
    - 2nd argument: nothing, node filter for link/style, nodes link/style. 
- sheets: returns the sheets that match the selector or all of them if none. 
- clean: converts a rule literal, to array of rules. 
- parent: returns the parent of a rule, neccesary for IE. 
- outerText: return the selector with the rules of the given rule. 
- text: gets/sets the cssText of the rule. 

jQuery.rule.fn 
- append: will add one or more styles in the form of "attr:value; attr:value" to the matched rules. 
- css : sets a value to all matched rules. 
- outerText: return $.rule.outerText of the first rule. 
- text: sets the cssText of the rules, or gets the cssText from the first one. 
- appendTo: appends the matched rules to the specified stylesheet(1), can be a selector, dom element, sheet. 

All these methods (from jQuery.rule.fn) are equal (or very similar) to those in jQuery.fn, but for CSS Rules. 
    add, andSelf, animate, appendTo, attr, css, dequeue, 
    each, end, eq, fadeIn, fadeOut, fadeTo, filter, get, 
    hide, index, is, map, not, pushStack, queue, remove, 
    setArray, show, size, slice, stop, toggle. 

Some calls to show and hide behave unexpectedly sometimes. Some styles and animations might fail. 

이 제발 도와주세요 :

문서는 말한다.

감사합니다.

참고 : jQuery에 대해 알고 있다면 쉽게 할 수 있지만 초보자라면 열심히 할 것이라고 확신합니다. Google에서이 문제에 대한 정보를 얻으려고 노력했지만 아무것도 찾을 수 없습니다. 나는 질문에 익숙하다 What you tried ?, 여기 나는 모른다. 제발 시작입니다. 고맙습니다 !

+1

예를 들면 현재 위치 : http://flesler.webs.com/jQuery.Rule/ –

+0

@AlanKuras는 그 이전에 확인하지만, 추가 할 수있는 방법을 찾을 수 없습니다 새로운 규칙, – Red

답변

2

기본 예 :이 예에서

$.rule('#some_id','style').append('font-size:17px'); 

의 규칙라는 이름의 CSS를 ID로 새로운 스타일을 추가 할 것 'SOME_ID'. 글꼴 크기를 17px로 설정하는 새로운 CSS 규칙을 추가합니다.

그래서 기본적으로 당신은 당신은 여기에 더 많은 예제를 얻을 수 있습니다 여기에 http://flesler.webs.com/jQuery.Rule/API.txt

을 설명 매개 변수 "$ .rule"키워드를 사용하여 새 규칙을 만드는 : http://flesler.webs.com/jQuery.Rule/ 물론

먼저 당신이 JQuery와이 플러그인을 포함해야 예를 들어 귀하의 문서. 이런 식으로 :

<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="jquery.rule.js"></script> 
+0

고마워 ... 그게 다야 !! – Red

+0

환영합니다. –

+0

이것은 작동하지 않습니다. #some_id에 이미 CSS 규칙이있는 경우에만 작동하는 것 같습니다. –

1

jQuery 규칙을 사용하지 마십시오. 설명서가 매우 좋지 않습니다. JSS는 훨씬 더 좋습니다 : https://github.com/Box9/jss. 어떻게 JSS에서 당신이 원하는 것을 할 :

jss('#some_id', { 
    fontSize: '17px' 
}); 
+1

트롤하지 말아라. 그러나 JSS의 문서는 훨씬 더 얇다. GitHub에보고 된 공개 된 문제 중 일부에 대해서는 플러그인이 자동으로 실패한다. jQuery.rule은 더 많은 기능을 제공하며 GitHub에 대해보고 된 문제가 없습니다. – Barney